2010-10-01 15 views
8

सी #हल करने के लिए कैसे: सी #

"अपवाद मंगलाचरण का लक्ष्य द्वारा फेंक दिया गया था" हर बार जब मैं अपने porgram चलाने मैं इस अपवाद: alt text

लेकिन जब मैं डिबग मोड में चलाने के लिए, वहाँ है कोई अपवाद नहीं है और कार्यक्रम ठीक काम करता है, मैं क्या कर सकता हूं?

नोट: मैं आह्वान() का उपयोग नहीं करते परियोजना में कहीं भी

संपादित करें: ठीक है, कोड विवरण में पाया जाता है: किसी protoBuff उपयोग करने के लिए कैसे पता है, और इस समस्या को जानते हैं ....

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

पंक्ति 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); 

       } 

मुझे यह नहीं मिल रहा है, क्या गलत है? क्या मुझे कोड का एक और हिस्सा जोड़ने की ज़रूरत है? शायद seraliztaion?

+5

विवरण पर क्लिक करके प्रारंभ करें और पूर्ण अपवाद और स्टैक ट्रेस देखें। –

+0

माइकल ने क्या किया। वास्तविक त्रुटि क्या है? –

+0

मैंने कोड जोड़ा, अगर आप पूर्ण चाहते हैं, तो बस मुझे बताएं। –

उत्तर

4

आप Protobuf का उपयोग कर रहे हैं जो कुछ समझ में नहीं आता है। शायद आपके असेंबली या डेटा के किसी अन्य संस्करण का उपयोग करके डेटा को क्रमबद्ध किया गया है जो आपके द्वारा पहले स्थान पर क्रमबद्ध नहीं है। Google प्रोटोकॉल बफर का उपयोग किसी ऑब्जेक्ट को आपकी ऑब्जेक्ट का प्रतिनिधित्व करने के लिए किया जा सकता है। आप ऑब्जेक्ट को फिर से बनाने के लिए स्ट्रीम को बाद में deserialize कर सकते हैं। हालांकि, यह महत्वपूर्ण है कि आप उसी तरह ऑब्जेक्ट को क्रमबद्ध और deserialize। यदि आप सिर्फ deserialization में कचरा खिलाते हैं तो आप अजीब अपवाद फेंक देंगे।

समस्या MainForm.cs पर होता है, लाइन 97.

जब आप को रिलीज़ मोड तो शायद फ़ाइल आप deserialize की कोशिश कर रहे द्विआधारी निर्देशिका और रिलीज़ मोड में स्थित है में चला आप केवल त्रुटि मिलती है फ़ाइल पुरानी है, यानी, इसमें आपके द्वारा क्रमबद्ध डेटा के पुराने संस्करण का क्रमबद्ध डेटा शामिल है।

+0

ठीक है मैंने मुख्य पोस्ट में एक अनुभाग जोड़ा है जो आपको –

27

TargetInvocationException आपको यह बताकर असली अपवाद मास्क करता है कि यह आमतौर पर something.Invoke के माध्यम से "एक विधि आमंत्रण" के दौरान दुर्घटनाग्रस्त हो जाता है।

आप अपवाद वस्तु (TargetInvocationException वस्तु) की InnerException संपत्ति देख रहा है क्या करना है, यह आप वास्तविक अपवाद है कि एक अधिक उपयोगी स्टैक ट्रेस के साथ फेंक दिया गया था, दे देंगे।

+1

पर एक टिप्पणी है जिसमें आंतरिक अपवाद के लिए मुझे यह हल करने के लिए आवश्यक सभी विवरण थे, यह वास्तव में मेरे मामले में 'अवैध कास्ट अपवाद' था। – Niklas

0

मेरे मामले में मैं एमडी 5 क्रिप्टोग्राफी का उपयोग कर रहा था जहां FIPS was enabled on server था। मैंने हैश की गणना करने के लिए SHA1 का उपयोग किया और यह मेरे लिए काम किया।

संबंधित मुद्दे