异常信息:System.Reflection.TargetInvocationException

Gib*_*boK 10 .net c# wpf system.reflection

我正在研究WPF应用程序,我只在运行时在单个设备上收到此错误.

Exception Info: System.Reflection.TargetInvocationException
Run Code Online (Sandbox Code Playgroud)

我的问题:

  • 任何可能导致此错误的线索?
  • 知道如何在发布模式下调试应用程序吗?

Exception Info: System.Reflection.TargetInvocationException
Stack:
   at System.RuntimeMethodHandle.InvokeMethod(System.Object, System.Object[], System.Signature, Boolean)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(System.Object, System.Object[], System.Object[])
   at System.Delegate.DynamicInvokeImpl(System.Object[])
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
   at System.Windows.Threading.DispatcherOperation.InvokeImpl()
   at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(System.Object)
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Windows.Threading.DispatcherOperation.Invoke()
   at System.Windows.Threading.Dispatcher.ProcessQueue()
   at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
   at MS.Win32.HwndWrapper.WndProc(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan, System.Delegate, System.Object, Int32)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr, Int32, IntPtr, IntPtr)
   at MS.Win32.UnsafeNativeMethods.DispatchMessage(System.Windows.Interop.MSG ByRef)
   at System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame)
   at System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame)
   at System.Windows.Threading.DispatcherOperation.Wait(System.TimeSpan)
   at System.Windows.Threading.Dispatcher.InvokeImpl(System.Windows.Threading.DispatcherOperation, System.Threading.CancellationToken, System.TimeSpan)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan, System.Delegate, System.Object, Int32)
   at WPF.DataModel.WPFDataSource.LoadData()
   at WPF.DataModel.WPFDataSource.DownloadNewData(Boolean)
   at WPF.DataModel.WPFDataSource.Load(Boolean)
   at WPF.App.OnStartup(System.Windows.StartupEventArgs)
   at System.Windows.Application.<.ctor>b__1(System.Object)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
   at System.Windows.Threading.DispatcherOperation.InvokeImpl()
   at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(System.Object)
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Windows.Threading.DispatcherOperation.Invoke()
   at System.Windows.Threading.Dispatcher.ProcessQueue()
   at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
   at MS.Win32.HwndWrapper.WndProc(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan, System.Delegate, System.Object, Int32)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr, Int32, IntPtr, IntPtr)
   at MS.Win32.UnsafeNativeMethods.DispatchMessage(System.Windows.Interop.MSG ByRef)
   at System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame)
   at System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame)
   at System.Windows.Threading.Dispatcher.Run()
   at System.Windows.Application.RunDispatcher(System.Object)
   at System.Windows.Application.RunInternal(System.Windows.Window)
   at System.Windows.Application.Run(System.Windows.Window)
   at WPF.App.Main()
Run Code Online (Sandbox Code Playgroud)

Mar*_*ell 16

这是一个包装器异常,只是告诉您反射.Invoke()(或类似)失败.要找出实际失败的内容,您需要查看包含的异常,通过.InnerException.那包含真正的错误.

所以:无论你在哪里捕捉它,只需检查ex.InnerException.而.InnerException这一点,如果一个人,等-一路下跌.


Nee*_*eel 5

你应该将这部分代码放在try/catch块中并捕获TargetInvocationException并查看内部异常它会给你更详细的理由

此异常可以提供有关问题的更多信息,这意味着反射.Invoke()失败.

欲获得更多信息 :-

正如官方网站http://support.microsoft.com/kb/828991所示: -

您收到System.Reflection.TargetInvocationException错误,因为公共语言运行库使用反射调用MethodInfo.Invoke方法.

使用Assembly.LoadFrom方法加载程序集时,公共语言运行库将加载的程序集放在应用程序的LoadFrom上下文中.对程序集依赖关系的任何探测首先探测当前应用程序目录.如果此探测失败,则公共语言运行库将探测应用程序的LoadFrom上下文.

您可以加载具有简单命名依赖项的程序集,该程序集与当前应用程序目录中的文件具有相同的文件名.当您尝试使用MethodInfo.Invoke方法调用已加载程序集中的方法,并且调用的方法使用该依赖项时,公共语言运行库首先探测当前目录路径.当公共语言运行库找到与依赖项具有相同文件名的文件时,探针将停止.但是,如果此文件与依赖项不具有相同的程序集标识,则程序集绑定将失败,并且公共语言运行库会生成传递给System.Reflection.TargetInvocationException错误的System.IO.FileLoadException错误.因此,您可能会注意到"症状"一节中提到的行为.