调用的目标已抛出异常 - vb.net
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24001686/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Exception has been thrown by the target of an invocation - vb.net
提问by John Janssen
I have an issue where I am receiving the error, "Exception has been thrown by the target of an invocation. I have the new
keyword in place. I made sure the ReportsData_Employee.COATSEndAssignmentDataTable
existed.
我有一个问题,我收到错误,“调用的目标抛出了异常。我有new
关键字。我确保ReportsData_Employee.COATSEndAssignmentDataTable
存在。
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& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, StackCrawlMark& 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:
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.
有人可以说出我可能收到此错误的其他一些原因吗?我查看了多个链接,但很多答案不适用于我的情况。
"Exception has been thrown by the target of an invocation" error (mscorlib)
FYI I have tried ReadOnly _xml_datatable as New ReportsData_Employee.COATSEndASsignmentDataTable()
and there was still an issue.
仅供参考,我已经尝试过ReadOnly _xml_datatable as New ReportsData_Employee.COATSEndASsignmentDataTable()
,但仍然存在问题。
Any help is appreciated. Let me know if there is any other information you need.
任何帮助表示赞赏。如果您需要任何其他信息,请告诉我。
Thanks.
谢谢。
采纳答案by T.S.
You haven't initialized object properly. Here...
您没有正确初始化对象。这里...
ReadOnly _xml_datatable As ReportsData_Employee.COATSEndAssignmentDataTable = New ReportsData_Employee.COATSEndAssignmentDataTable()
Should be
应该
Private ReadOnly _xml_datatable As New ReportsData_Employee.COATSEndAssignmentDataTable()
Your real issue is
你真正的问题是
InnerException: System.NullReferenceException
HResult=-2147467261
Message=Object reference not set to an instance of an object.
Source=Advance.Extensions.Activities
You need to look into constructor of COATSEndAssignmentDataTable
. you have NullReferenceException
in there. These two lines tell you exact location
您需要查看COATSEndAssignmentDataTable
. 你NullReferenceException
在那里。这两行告诉你确切的位置
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