How to solve: “exception was thrown by the target of invocation” C#

前端 未结 4 467
生来不讨喜
生来不讨喜 2020-12-10 12:18

C#

Every time I run my porgram I get this exception: \"alt

But when I run in debug mode, there i

相关标签:
4条回答
  • 2020-12-10 12:38

    For me, had some null references in the OnLoad() of a XAML project (and it threw OP's nebulous error). Just as Lasse Vågsæther Karlsen answered, looking at the inner exception's stacktrace got me to the line number.

    0 讨论(0)
  • 2020-12-10 12:42

    In My case i was using MD5 cryptography where as FIPS was enabled on server. I used SHA1 to calculate hash and its worked for me.

    0 讨论(0)
  • 2020-12-10 12:43

    You are using Protobuf to deserialize something it doesn't understand. Probably data serialized using another version of your assembly or data not serialized by you in the first place. Google Protocol Buffers can be used to write a representation of your object to a stream. You can later deserialize the stream to recreate the object. However, it is important that you serialize and deserialize the object in the same way. If you just feed garbage into the deserialization you will get weird exceptions thrown.

    The problem occurs at MainForm.cs, line 97.

    If you only get the error when you run in release mode then perhaps the file you are trying to deserialize is located in the binary directory and the release mode file is out of date, that is, it contains serialized data of an older version of the data you are serializing.

    0 讨论(0)
  • 2020-12-10 12:50

    TargetInvocationException masks the real exception by telling you that it crashed during "a method invocation", usually through something.Invoke.

    What you have to do is look at the InnerException property of the exception object (the TargetInvocationException object), this will give you the actual exception that was thrown, with a more useful stack trace.

    0 讨论(0)
提交回复
热议问题