Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何解决:“;调用的目标引发了异常";C#_C#_.net_Exception - Fatal编程技术网

如何解决:“;调用的目标引发了异常";C#

如何解决:“;调用的目标引发了异常";C#,c#,.net,exception,C#,.net,Exception,C# 每次运行程序时,我都会遇到以下异常: 但是当我在调试模式下运行时,没有异常,程序运行良好,我能做什么 注意:我没有在项目中的任何地方使用invoke() 编辑:好的,下面是详细信息中的代码: 如果有人知道如何使用protoBuff,并且知道这个问题 ************** Exception Text ************** System.Reflection.TargetInvocationException: Exception has been thrown b

C#

每次运行程序时,我都会遇到以下异常:

但是当我在调试模式下运行时,没有异常,程序运行良好,我能做什么

注意:我没有在项目中的任何地方使用invoke()

编辑:好的,下面是详细信息中的代码: 如果有人知道如何使用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?

您正在使用
Protobuf
对它不理解的内容进行反序列化。可能是使用程序集的另一个版本序列化的数据,或者是最初未序列化的数据。Google协议缓冲区可用于将对象的表示写入流。稍后可以反序列化流以重新创建对象。但是,必须以相同的方式序列化和反序列化对象。如果您只是将垃圾送入反序列化,您将抛出奇怪的异常

问题出现在MainForm.cs的第97行

如果仅在以发布模式运行时出现错误,则可能您尝试反序列化的文件位于二进制目录中,并且发布模式文件已过期,也就是说,它包含正在序列化的数据的旧版本的序列化数据。

通过告诉您它在“方法调用”,通常通过
某物调用


您需要做的是查看异常对象(对象)的属性,这将为您提供抛出的实际异常,以及更有用的堆栈跟踪。

在我的示例中,我使用的是MD5加密,其中as。
我使用SHA1计算散列,它对我有用。

对我来说,在XAML项目的OnLoad()中有一些空引用(它抛出了OP模糊的错误).正如Lasse Vågsæther Karlsen回答的那样,查看内部异常的stacktrace让我找到了行号。

首先单击详细信息,查看完整的异常和堆栈跟踪。按照Michael说的做。实际错误是什么?我添加了代码,如果您想要完整的,请告诉我。可能是bin\Debug文件夹中存在的文件但不在bin\Release文件夹中。它应该在两者中都存在?好吧,我在主要帖子中添加了一个部分,是对youinner exception的评论。我已经获得了解决此问题所需的所有详细信息,在我的情况下,它确实是一个
无效的强制转换异常
。是的,但是
InnerException
缺少行号(正好引发异常的位置),为什么?我从加载的程序集调用方法,程序集是在调试模式下生成的。