title: Exception has been thrown by the target of an invocation - vb.net
body: <p>I have an issue where I am receiving the error, "Exception has been thrown by the target of an invocation.  I have the <code>new</code> keyword in place.  I made sure the <code>ReportsData_Employee.COATSEndAssignmentDataTable</code> existed.  </p>
  
  <pre><code>    Imports System.Windows.Forms
      Imports Advance.Extensions.Reporting
      Imports CrystalDecisions.Shared
      Imports Advance.Common.Reporting
      Imports System.IO
  
      Public Class Activity_EndAssignmentTool
          ReadOnly _dt As New DataTable
          Dim _dts As New DataTable
          Dim _bldts As New DataTable
          Dim _xml_file_name_creation As String
      '// This is the line that is causing the error ============
          ReadOnly _xml_datatable As ReportsData_Employee.COATSEndAssignmentDataTable = New ReportsData_Employee.COATSEndAssignmentDataTable()
      '//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  
     ====================================================================================== 
  
     System.Reflection.TargetInvocationException was caught
     HResult=-2146232828
     Message=Exception has been thrown by the target of an invocation.
     Source=mscorlib
     StackTrace:
     at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly,        Boolean noCheck, Boolean&amp; canBeCached, RuntimeMethodHandleInternal&amp; ctor, Boolean&amp; bNeedSecurityCheck)
     at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark&amp; stackMark)
     at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark&amp; stackMark)
     at System.Activator.CreateInstance(Type type, Boolean nonPublic)
     at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, StackCrawlMark&amp; stackMark)
     at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
     at System.Reflection.Assembly.CreateInstance(String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
     at System.Reflection.Assembly.CreateInstance(String typeName)
     at Advance.Extensions.Activities.Activity_Form.GetActivityForm(String className) in C:\Users\JJanssen\Documents\Visual Studio 2010\Projects\Legacy\Advance Extensions\advance.extensions.activities\Forms\Activity_Form.vb:line 126
     at Advance.Extensions.Activities.Activity_Form.SetActivityClass() in C:\Users\JJanssen\Documents\Visual Studio 2010\Projects\Legacy\Advance Extensions\advance.extensions.activities\Forms\Activity_Form.vb:line 60
     InnerException: System.NullReferenceException
     HResult=-2147467261
     Message=Object reference not set to an instance of an object.
     Source=Advance.Extensions.Activities
     StackTrace:
     at Advance.Extensions.Activities.Activity_EndAssignmentTool.InitializeComponent() in C:\Users\JJanssen\Documents\Visual Studio 2010\Projects\Legacy\Advance Extensions\advance.extensions.activities\Activity_Forms\Activity_EndAssignmentTool.Designer.vb:line 479
     at Advance.Extensions.Activities.Activity_EndAssignmentTool..ctor() in C:\Users\JJanssen\Documents\Visual Studio 2010\Projects\Legacy\Advance Extensions\advance.extensions.activities\Activity_Forms\Activity_EndAssignmentTool.vb:line 12
     InnerException: 
  </code></pre>
  
  <p>Can someone name some other reasons why I could be getting this error?  I have looked at multiple links but a lot of the answers don't apply in my situation.</p>
  
  <p><a href="https://stackoverflow.com/questions/648113/exception-has-been-thrown-by-the-target-of-an-invocation-error-mscorlib">&quot;Exception has been thrown by the target of an invocation&quot; error (mscorlib)</a></p>
  
  <p>FYI I have tried <code>ReadOnly _xml_datatable as New ReportsData_Employee.COATSEndASsignmentDataTable()</code> and there was still an issue.</p>
  
  <p>Any help is appreciated.  Let me know if there is any other information you need.</p>
  
  <p>Thanks.</p>