title: SSIS Element cannot be found in a collection (but I have them all listed!)
body: <p>I'm getting a persistent error:</p>
  
  <blockquote>
    <p>The element cannot be found in a collection.<br>
    This error happens when you try to retrieve an element from a collection on a container during execution of the package and the element is not there.</p>
  </blockquote>
  
  <p>I've checked, double and triple-checked my variable listings in the Read-Only and Read-Write variables in my Script task.
  I've debugged it to death and gotten input from another programmer here who couldn't spot the issue either.
  I've also researched to no end.</p>
  
  <ul>
  <li>Does anyone see anything wrong with my code?</li>
  </ul>
  
  <p>Script Task code:</p>
  
  <pre><code>Public Sub Main()
      Dts.Variables("User::strMailBody").Value = "Thank you for submission. For your convenience, we are including the last four of the HICN# and the Name on the application(s) we have received* from you." _
          &amp; vbNewLine &amp; vbNewLine &amp; "Here are the following: " &amp; vbNewLine &amp; vbNewLine
      Dts.Variables("User::strMailBody").Value = Dts.Variables("User::strMailbody").Value.ToString() &amp; vbNewLine &amp; Dts.Variables("User::strListing").Value.ToString()
      Dts.Variables("User::strMailBody").Value = Dts.Variables("User::strMailBody").Value.ToString() &amp; vbNewLine &amp; vbNewLine &amp; Dts.Variables("User::strFooter").Value.ToString()
  
      If Left(Dts.Variables("User::strAgentID").Value, 2) = "TX" Then
          Dts.Variables("User::strSubject").Value = "ACME Health Plans Confirmation:  Total "
      Else
          Dts.Variables("User::strSubject").Value = "ACME2 Baptist Health Plans Confirmation:  Total "
      End If
  
      Dts.Variables("User::strSubject").Value = Dts.Variables("User::strSubject").Value.ToString() &amp; Dts.Variables("User::lngCountAgent").Value.ToString() &amp; "   " &amp; "[RESTRICTED: CONFIDENTIAL]"
      Dts.Variables("User::DateSent").Value = Now()
      Dts.Variables("User::UserSent").Value = "SSIS"
  
      Dts.TaskResult = ScriptResults.Success
  End Sub
  </code></pre>