我的反序列函数总是跑出异常,我接收了一个byte[],反序列化时说找不到程序集“xxx.exe version:1.0.0”什么的
public static object BytesToObject(byte[] p_ObjectBytes)
{
BinaryFormatter _Formatter = new BinaryFormatter();
MemoryStream _MemStr = new MemoryStream(p_ObjectBytes);
_MemStr.Position = 0;
try
{
return _Formatter.Deserialize(_MemStr);
}
catch(Exception e)
{
Console.WriteLine(e.Message);
return null;
}
}
public static object BytesToObject(byte[] p_ObjectBytes)
{
BinaryFormatter _Formatter = new BinaryFormatter();
MemoryStream _MemStr = new MemoryStream(p_ObjectBytes);
_MemStr.Position = 0;
try
{
return _Formatter.Deserialize(_MemStr);
}
catch(Exception e)
{
Console.WriteLine(e.Message);
return null;
}
}
还有p_ObjectBytes数据获取是否存在问题
例如:[Serializable] ----------------指示一个类可以序列化,无法继承此类
class MemoryStream ----------------你创建的那个MemoryStream类
{
public string stuName;
public int stuAge;
}另外还要有using System.Runtime.Serialization.Formatters.Binary;这句引用
一周没看了,今天再看就搞懂了,呵呵