C# 4.0 反序列化时出现异常。无法加载类型system.Collection.Generic.Dictionary';2.
有一个excel插件,可以与我正在开发的主应用程序进行通信。我将序列化对象发送到插件,我似乎无法反序列化该对象。我得到如下所示的异常。请帮忙 对象已成功发送,但问题是对其进行反序列化。 这是我从中接收对象的代码C# 4.0 反序列化时出现异常。无法加载类型system.Collection.Generic.Dictionary';2.,c#-4.0,serialization,C# 4.0,Serialization,有一个excel插件,可以与我正在开发的主应用程序进行通信。我将序列化对象发送到插件,我似乎无法反序列化该对象。我得到如下所示的异常。请帮忙 对象已成功发送,但问题是对其进行反序列化。 这是我从中接收对象的代码 public void PipeIn(string sender, MessageType messageType, byte[] eventClass) { if (DataReady != null) {
public void PipeIn(string sender, MessageType messageType, byte[] eventClass)
{
if (DataReady != null)
{
MemoryStream stream = new MemoryStream(eventClass);
try
{
var deserializedObj = _binFormatter.Deserialize(stream);
DataReady(sender, messageType, deserializedObj);
}
catch (Exception _e)
{
throw;
}
finally
{
stream.Close();
}
}
}
这是我用来序列化对象的方法
var stream = new MemoryStream();
byte[] objectByteArr = null;
try
{
//Serialize the object into the stream
_binFormatter.Serialize(stream, eventType);
//Copy the bytes from the stream to the byte array
objectByteArr = stream.ToArray();
if (objectByteArr.Length >= 536870912)
{
MessageBox.Show("The Data Exceeds the max size of 536870912", "Too Big", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation);
}
}
catch (Exception _e)
{
}
finally
{
stream.Close();
}
你能告诉我们你是如何序列化的吗?我认为序列化和反序列化对象的方式可能有所不同。您能编辑您的问题并在其中添加序列化代码吗?在注释中看不到它。@dhrumilap这是我序列化的方式var stream=newmemoryStream()_序列化(流,事件类型);objectByteArr=stream.ToArray();'@dhrumilap谢谢你,很抱歉我不习惯堆叠溢出。现在就在上面