2014-06-09 16 views
10

Tôi đang làm việc trên một ứng dụng WPF, tôi nhận được lỗi này chỉ khi chạy trên một thiết bị duy nhất.Thông tin ngoại lệ: System.Reflection.TargetInvocationException

Exception Info: System.Reflection.TargetInvocationException 

Câu hỏi của tôi:

  • Bất kỳ manh mối của những gì có thể gây ra lỗi này?
  • Bất kỳ ý tưởng nào về cách gỡ lỗi ứng dụng ở chế độ phát hành?

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

Trả lời

13

Đó là một ngoại lệ wrapper mà chỉ đơn giản nói với bạn rằng một sự phản ánh .Invoke() (hoặc tương tự) thất bại. Để tìm hiểu những gì thực sự không thành công, bạn cần phải nhìn vào trường hợp ngoại lệ được bao bọc, thông qua .InnerException. Có chứa lỗi thực.

Vì vậy: khi nào bạn bắt được điều đó, chỉ cần kiểm tra ex.InnerException. Và .InnerException của điều đó, nếu một, vv - tất cả các con đường xuống.

5

Bạn nên đặt phần này của mã bên trong khối try/catch và bắt TargetInvocationException và xem ngoại lệ bên trong nó sẽ cho bạn lý do chi tiết hơn

ngoại lệ này có thể cung cấp thêm thông tin vấn đề là gì và nó có nghĩa là sự phản ánh .Invoke() không thành công.

Để biết thêm thông tin: -

Như đã đề cập trong trang web chính thức ở đây http://support.microsoft.com/kb/828991: -

Bạn nhận được lỗi System.Reflection.TargetInvocationException vì thời gian chạy ngôn ngữ chung gọi phương thức MethodInfo.Invoke bằng cách sử dụng sự phản chiếu.

Khi bạn tải lắp ráp bằng cách sử dụng phương thức Assembly.LoadFrom, thời gian chạy ngôn ngữ phổ biến đặt cụm được tải trong ngữ cảnh LoadFrom của ứng dụng của bạn. Bất kỳ đầu dò nào cho các phụ thuộc của hội đồng đầu tiên sẽ thăm dò thư mục ứng dụng hiện tại. Nếu thăm dò này không thành công, thời gian chạy ngôn ngữ phổ biến sau đó thăm dò ngữ cảnh LoadFrom của ứng dụng của bạn.

Bạn có thể tải một hội đồng có phụ thuộc đơn giản có tên là cùng tên tệp dưới dạng tệp trong thư mục ứng dụng hiện tại. Khi bạn cố gắng gọi một phương thức trong hội đồng được nạp bằng cách sử dụng phương thức MethodInfo.Invoke và phương thức được gọi sử dụng phụ thuộc, thời gian chạy ngôn ngữ chung đầu tiên thăm dò đường dẫn thư mục hiện tại. Khi thời gian chạy ngôn ngữ chung tìm thấy tệp có cùng tên tên là phụ thuộc, đầu dò dừng lại. Tuy nhiên, nếu tệp này không không có cùng một định danh lắp ráp làm phụ thuộc, việc lắp ráp liên kết không thành công và thời gian chạy ngôn ngữ phổ biến tạo ra lỗi Lỗi System.IO.FileLoadException được chuyển tới lỗi System.Reflection.TargetInvocationException.Do đó, bạn có thể nhận thấy hành vi được đề cập trong phần "Triệu chứng".

Các vấn đề liên quan