C# 异常信息:System.Reflection.TargetInvocationException

C# 异常信息:System.Reflection.TargetInvocationException,c#,.net,wpf,system.reflection,C#,.net,Wpf,System.reflection,我正在处理一个WPF应用程序,只有在单个设备上运行时才会收到此错误 Exception Info: System.Reflection.TargetInvocationException 我的问题: 有没有线索表明是什么导致了这个错误 知道如何在发布模式下调试应用程序吗 异常信息:System.Reflection.TargetInvocationException 堆栈: 位于System.RuntimeMethodHandle.InvokeMethod(System.Object,S

我正在处理一个WPF应用程序,只有在单个设备上运行时才会收到此错误

Exception Info: System.Reflection.TargetInvocationException
我的问题:

  • 有没有线索表明是什么导致了这个错误
  • 知道如何在发布模式下调试应用程序吗

异常信息:System.Reflection.TargetInvocationException 堆栈: 位于System.RuntimeMethodHandle.InvokeMethod(System.Object,System.Object[],System.Signature,布尔值) 位于System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(System.Object,System.Object[],System.Object[]) 位于System.Delegate.DynamicInvokeImpl(System.Object[]) 位于System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate、System.Object、Int32) 位于MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object、System.Delegate、System.Object、Int32、System.Delegate) 在System.Windows.Threading.DispatcherOperation.InvokeImpl()中 位于System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(System.Object) 位于System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext,System.Threading.ContextCallback,System.Object,布尔值) 在System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext,System.Threading.ContextCallback,System.Object,布尔值) 在System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext,System.Threading.ContextCallback,System.Object)上运行 在System.Windows.Threading.DispatcherOperation.Invoke()中 在System.Windows.Threading.Dispatcher.ProcessQueue()中 位于System.Windows.Threading.Dispatcher.WndProcHook(IntPtr、Int32、IntPtr、IntPtr、Boolean ByRef) 位于MS.Win32.hwndwapper.WndProc(IntPtr、Int32、IntPtr、IntPtr、Boolean ByRef) 位于MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object) 位于System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate、System.Object、Int32) 位于MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object、System.Delegate、System.Object、Int32、System.Delegate) 位于System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority,System.TimeSpan,System.Delegate,System.Object,Int32) 在MS.Win32.HwndSubclass.SubclassWndProc(IntPtr,Int32,IntPtr,IntPtr) 位于MS.Win32.unsafentivemethods.DispatchMessage(System.Windows.Interop.MSG ByRef) 位于System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame) 位于System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame) 位于System.Windows.Threading.DispatcherOperation.Wait(System.TimeSpan) 位于System.Windows.Threading.Dispatcher.InvokeImpl(System.Windows.Threading.DispatcherOperation,System.Threading.CancellationToken,System.TimeSpan) 位于System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority,System.TimeSpan,System.Delegate,System.Object,Int32) 在WPF.DataModel.WPFDataSource.LoadData()处 在WPF.DataModel.WPFDataSource.DownloadNewData(布尔值) 在WPF.DataModel.WPFDataSource.Load处(布尔值) 在WPF.App.OnStartup(System.Windows.StartupEventArgs)上 在System.Windows.Application.b__1(System.Object)中 位于System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate、System.Object、Int32) 位于MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object、System.Delegate、System.Object、Int32、System.Delegate) 在System.Windows.Threading.DispatcherOperation.InvokeImpl()中 位于System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(System.Object) 位于System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext,System.Threading.ContextCallback,System.Object,布尔值) 在System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext,System.Threading.ContextCallback,System.Object,布尔值) 在System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext,System.Threading.ContextCallback,System.Object)上运行 在System.Windows.Threading.DispatcherOperation.Invoke()中 在System.Windows.Threading.Dispatcher.ProcessQueue()中 位于System.Windows.Threading.Dispatcher.WndProcHook(IntPtr、Int32、IntPtr、IntPtr、Boolean ByRef) 位于MS.Win32.hwndwapper.WndProc(IntPtr、Int32、IntPtr、IntPtr、Boolean ByRef) 位于MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object) 位于System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate、System.Object、Int32) 位于MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object、System.Delegate、System.Object、Int32、System.Delegate) 位于System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority,System.TimeSpan,System.Delegate,System.Object,Int32) 在MS.Win32.HwndSubclass.SubclassWndProc(IntPtr,Int32,IntPtr,IntPtr) 位于MS.Win32.unsafentivemethods.DispatchMessage(System.Windows.Interop.MSG ByRef) 位于System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame) 位于System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame) 在System.Windows.Threading.Dispatcher.Run()中 位于System.Windows.Application.RunDispatcher(System.Object) 位于System.Windows.Application.RunInternal(System.Windows.Window) 在System.Windows.Application.Run(System.Windows.Window)中 在WPF.App.Main()处
这是一个包装异常,它简单地告诉您反射
.Invoke()
(或类似)失败。要找出实际失败的原因,您需要通过
.InnerException
查看包装的异常。这包含了真正的错误


所以:无论您在何处捕捉到这种情况,只要检查
ex.InnerException
。还有
.InnerException
,如果有,等等-一直往下看。

你应该把这部分代码放在try/catch块和catch TargetInvocationException中,看看内部异常,它会给你更详细的结果
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()