web-dev-qa-db-ja.com

例外情報:System.Reflection.TargetInvocationException

WPFアプリケーションで作業していますが、このエラーは単一のデバイスで実行時にのみ表示されます。

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()
11
GibboK

これは、リフレクション.Invoke()(または同様のもの)が失敗したことを単に通知するラッパー例外です。 実際に失敗したものを見つけるには、.InnerExceptionを介してラップされた例外を確認する必要があります。 realエラーが含まれています。

つまり、どこにいても、それをキャッチしている場合は、ex.InnerExceptionを確認してください。そして、その.InnerException、もしあれば、など-ずっと下に。

17
Marc Gravell

コードのこの部分をtry/catchブロック内に配置し、TargetInvocationExceptionをキャッチして、より詳細な理由を示す内部例外を確認する必要があります

この例外は、問題が何であるかについてより多くの情報を提供することができ、リフレクション.Invoke()が失敗したことを意味します。

詳細については :-

ここの公式サイトで提案されているように http://support.Microsoft.com/kb/828991 :-

共通言語ランタイムがリフレクションを使用してMethodInfo.Invokeメソッドを呼び出すため、System.Reflection.TargetInvocationExceptionエラーが発生します。

Assembly.LoadFromメソッドを使用してアセンブリをロードすると、共通言語ランタイムは、ロードされたアセンブリをアプリケーションのLoadFromコンテキストに配置します。アセンブリの依存関係をプローブする場合は、最初に現在のアプリケーションディレクトリをプローブします。このプローブが失敗した場合、共通言語ランタイムはアプリケーションのLoadFromコンテキストをプローブします。

現在のアプリケーションディレクトリ内のファイルと同じファイル名を持つ、単純な名前の依存関係を持つアセンブリをロードできます。 MethodInfo.Invokeメソッドを使用して、ロードされたアセンブリ内のメソッドを呼び出そうとし、呼び出されたメソッドが依存関係を使用する場合、共通言語ランタイムは最初に現在のディレクトリパスをプローブします。共通言語ランタイムが依存関係と同じファイル名を持つファイルを見つけると、プローブは停止します。ただし、このファイルのアセンブリIDが依存関係と同じでない場合、アセンブリバインドは失敗し、共通言語ランタイムはSystem.IO.FileLoadExceptionエラーを生成し、これがSystem.Reflection.TargetInvocationExceptionエラーに渡されます。したがって、「症状」セクションに記載されている動作に気付く場合があります。

5
Neel