2010-10-01 77 views
8

C#Làm thế nào để giải quyết: "ngoại lệ được ném bởi mục tiêu của invocation" C#

Mỗi lần tôi chạy porgram của tôi, tôi có được ngoại lệ này: alt text

Nhưng khi tôi chạy trong chế độ gỡ lỗi, có không có ngoại lệ và chương trình hoạt động tốt, tôi có thể làm gì?

LƯU Ý: tôi không sử dụng invoke() bất cứ nơi nào trong dự án

EDIT: Được rồi, đây là mã được tìm thấy trong các chi tiết: Nếu ai đó biết làm thế nào để sử dụng protoBuff, và biết vấn đề này ....

************** Exception Text ************** 
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> ProtoBuf.ProtoException: Incorrect wire-type deserializing TimeSpan 
    at ProtoBuf.ProtoBcl.ProtoTimeSpan.DeserializeTicks(SerializationContext context) in c:\protobuf-net_fixed\trunk\protobuf-net\ProtoBcl\ProtoTimeSpan.cs:line 80 
    at ProtoBuf.ProtoBcl.ProtoTimeSpan.DeserializeDateTime(SerializationContext context) in c:\protobuf-net_fixed\trunk\protobuf-net\ProtoBcl\ProtoTimeSpan.cs:line 41 
    at ProtoBuf.Property.PropertyDateTimeString`1.DeserializeImpl(TSource source, SerializationContext context) in c:\protobuf-net_fixed\trunk\protobuf-net\Property\PropertyDateTimeString.cs:line 32 
    at ProtoBuf.Property.Property`2.Deserialize(TSource source, SerializationContext context) in c:\protobuf-net_fixed\trunk\protobuf-net\Property\Property.cs:line 150 
    at ProtoBuf.Serializer`1.Deserialize[TCreation](T& instance, SerializationContext context) in c:\protobuf-net_fixed\trunk\protobuf-net\SerializerT.cs:line 568 
    at ProtoBuf.Serializer`1.DeserializeChecked[TCreation](T& instance, SerializationContext source) in c:\protobuf-net_fixed\trunk\protobuf-net\SerializerT.cs:line 400 
    at ProtoBuf.SerializerItemProxy`2.Deserialize(TActualClass& instance, SerializationContext source) in c:\protobuf-net_fixed\trunk\protobuf-net\SerializerProxy.cs:line 86 
    at ProtoBuf.Serializer.Deserialize[T](SerializationContext source) in c:\protobuf-net_fixed\trunk\protobuf-net\Serializer.cs:line 302 
    at ProtoBuf.Serializer.Deserialize[T](Stream source) in c:\protobuf-net_fixed\trunk\protobuf-net\Serializer.cs:line 289 
    --- End of inner exception stack trace --- 
    at System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner) 
    at System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeType typeOwner) 
    at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) 
    at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) 
    at ProtoBuf.Serializer.NonGeneric.Deserialize(Type type, Stream source) in c:\protobuf-net_fixed\trunk\protobuf-net\NonGeneric.cs:line 154 
    at ProtoBuf.Serializer.NonGeneric.TryDeserializeWithLengthPrefix(Stream source, PrefixStyle style, Getter`2 typeReader, Object& item) in c:\protobuf-net_fixed\trunk\protobuf-net\NonGeneric.cs:line 128 
    at AccessPoint.MainForm.getEventsList() in C:\Users\user\Desktop\accesspoint\AccessPoint\AccessPoint\MainForm.cs:line 97 
    at AccessPoint.MainForm.Form1_Load(Object sender, EventArgs e) in C:\Users\user\Desktop\accesspoint\AccessPoint\AccessPoint\MainForm.cs:line 18 
    at System.Windows.Forms.Form.OnLoad(EventArgs e) 
    at System.Windows.Forms.Form.OnCreateControl() 
    at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible) 
    at System.Windows.Forms.Control.CreateControl() 
    at System.Windows.Forms.Control.WmShowWindow(Message& m) 
    at System.Windows.Forms.Control.WndProc(Message& m) 
    at System.Windows.Forms.ScrollableControl.WndProc(Message& m) 
    at System.Windows.Forms.Form.WmShowWindow(Message& m) 
    at System.Windows.Forms.Form.WndProc(Message& m) 
    at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) 
    at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) 
    at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) 

Row 97:

int startIndex = count - 10, index = 0; 
       object obj; 
       while (Serializer.NonGeneric.TryDeserializeWithLengthPrefix(file, PrefixStyle.Base128, tag => 
       { 
        return index++ >= startIndex ? typeof(EventsWireFrame) : null; 
       }, out obj)) 
       { 
        EventsWireFrame evt = (EventsWireFrame)obj; 
        AddEventToTable(evt.eventDate, evt.eventType, evt.eventKeyNumber, evt.eventKeyName, evt.eventDoor, true); 

       } 

Tôi không hiểu, có chuyện gì vậy? Tôi có cần phải thêm một phần mã khác không? Có lẽ seraliztaion?

+5

Bắt đầu bằng cách nhấp vào Chi tiết và xem xét toàn bộ ngoại lệ và theo dõi ngăn xếp. –

+0

Làm những gì Michael nói. Lỗi thực tế là gì? –

+0

Tôi đã thêm mã, nếu bạn muốn đầy đủ, chỉ cần cho tôi biết. –

Trả lời

4

Bạn đang sử dụng Protobuf để deserialize một cái gì đó nó không hiểu. Có lẽ dữ liệu được tuần tự hóa bằng cách sử dụng một phiên bản khác của hội đồng của bạn hoặc dữ liệu không được sắp xếp theo thứ tự của bạn ở nơi đầu tiên. Bộ đệm giao thức của Google có thể được sử dụng để viết biểu diễn đối tượng của bạn vào luồng. Sau đó bạn có thể deserialize dòng để tạo lại đối tượng. Tuy nhiên, điều quan trọng là bạn serialize và deserialize đối tượng trong cùng một cách. Nếu bạn chỉ cần đổ rác vào deserialization bạn sẽ nhận được ngoại lệ lạ ném.

Vấn đề xảy ra ở MainForm.cs, dòng 97.

Nếu bạn chỉ nhận được lỗi khi bạn chạy ở chế độ phát hành thì có lẽ tập tin bạn đang cố gắng deserialize nằm trong thư mục nhị phân và phương thức phát hành tệp đã lỗi thời, có nghĩa là, nó chứa dữ liệu được tuần tự hóa của một phiên bản cũ hơn của dữ liệu mà bạn đang tuần tự hóa.

+0

Ok Tôi đã thêm một phần trong bài đăng chính là nhận xét cho bạn –

27

TargetInvocationException mặt nạ ngoại lệ thực bằng cách cho bạn biết rằng nó bị lỗi trong "lời gọi phương thức", thường thông qua something.Invoke.

Những gì bạn phải làm là xem xét thuộc tính InnerException của đối tượng ngoại lệ (đối tượng TargetInvocationException), điều này sẽ cung cấp cho bạn ngoại lệ thực tế đã được ném, với dấu vết ngăn xếp hữu ích hơn.

+1

ngoại lệ bên trong có tất cả các chi tiết cần thiết để giải quyết vấn đề này cho tôi, đó thực sự là một 'Ngoại lệ Cast không hợp lệ' trong trường hợp của tôi. – Niklas

0

Trong trường hợp của tôi, tôi đã sử dụng mật mã MD5 ở đâu là FIPS was enabled on server. Tôi đã sử dụng SHA1 để tính toán giá trị băm và nó làm việc cho tôi.

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