title: Exception has been thrown by the target of an invocation
body: <p>I know this is a relatively common error but I am working in an application that allows custom reports to be written using vb.net or C# for scripting. Error handling is very poor and I am not knowledgable enough to add my own (if it is even possible).</p>
  
  <p>My code simply retrieves a value that is stored in a textbox on the report formatted as <em>LastName, FirstName</em> and truncates all characters after the comma. This value <em>LastName</em> is placed in a new textbox on the report. Here is my code:</p>
  
  <pre><code>Sub Detail1_Format
  
      Dim lastNameFirstName As String = ""
      Dim lastName As String = ""
      Dim lastNameCommaIndex As Integer=
  
  'set lastNameFirstName value from data on report'
      lastNameFirstName = ReportUtilities.ReturnTextBoxValue(rpt,"Detail1","txtdtr_DTOOLS_CompanyName")
  
  'find index of first comma in lastNameFirstName string'
      lastNameCommaIndex = lastNameFirstName.IndexOf(",")
  
  'set contents of lastName using substring of lastNameFirstString'
      lastName = lastNameFirstName.SubString(0, lastNameCommaIndex)
  'the error happens above when I use lastNameCommaIndex'
  'to set the number of characters in my substring'
  
  'set client name textbox value using lastName'
      ReportUtilities.SetTextBoxValue(rpt,"Detail1","txtdtr_CALC_ClientName",lastName)
  
  End Sub
  </code></pre>
  
  <p>The error happens when I use lastNameCommaIndex to set the number of characters in my substring. If I replace it with a number the report is published properly.</p>