2014-06-09 613 views
10

我工作的一個WPF應用程序中,我只在單個設備上運行時收到此錯誤。異常信息:System.Reflection.TargetInvocationException

Exception Info: System.Reflection.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() 

回答

13

這是一個包裝異常簡單地告訴你,一個反射.Invoke()(或類似)失敗。要了解實際上失敗,你需要看一下包裝的異常,通過.InnerException。包含實際錯誤。

所以:這裏,你永遠都不禁,只是檢查ex.InnerException。而且,如果有的話,等等 - 一路下來。

5

,你應該把try/catch塊內這部分代碼,趕上TargetInvocationException,看到了內部異常,它會給你更詳細的原因

這種異常可以提供更多的信息是什麼問題,這意味着反射.Invoke()失敗。

欲瞭解更多信息: -

正如在這裏官方網站建議http://support.microsoft.com/kb/828991: -

你,因爲公共語言運行庫調用MethodInfo.Invoke方法收到System.Reflection.TargetInvocationException錯誤 通過使用反射。

使用Assembly.LoadFrom方法加載程序集時, 公共語言運行庫會將加載的程序集置於應用程序的LoadFrom 上下文中。任何針對 程序集相關性的探針都會首先探測當前的應用程序目錄。如果此探針 失敗,公共語言運行庫將探測您的應用程序的 的LoadFrom上下文。

您可以加載一個具有簡單名稱依賴關係的程序集,該程序集具有與當前應用程序目錄中的文件相同的文件名 。 當您嘗試使用 MethodInfo.Invoke方法調用中加載的程序集的方法和調用的方法使用依賴, 公共語言運行庫首先探測當前目錄路徑。 當公共語言運行時查找具有相同的文件名 作爲相關性的文件,探測將停止。但是,如果 不具有與依賴關係相同的程序集標識,程序集 綁定失敗,並且公共語言運行時會生成 System.IO.FileLoadException錯誤,該錯誤傳遞給 System.Reflection.TargetInvocationException錯誤。因此,您可能會注意到「症狀」一節中提到的行爲 。