大家帮忙看看,报错“在分析完成之前就遇到流结尾。”
序列化:
public bool Serialization(Hashtable hashtable)
{
BinaryFormatter binaryFormatter = new BinaryFormatter();
System.IO.MemoryStream ms = new System.IO.MemoryStream();
binaryFormatter.Serialize(ms, hashtable);//内存流二级制序列化
ms.Position = 0;
byte[] b = new Byte[ms.Length];
ms.Read(b, 0, b.Length);
bool flag = new Product().ss(b);
ms.Close();
return flag; }下面是反序列化:
byte[] b = new Product().returnSeirazation();//数据库返回
System.IO.MemoryStream ms = new System.IO.MemoryStream(b);
BinaryFormatter binaryFormatter = new BinaryFormatter();
ms.Position = 0;
Items =(Hashtable)binaryFormatter.Deserialize(ms);//报错 在分析完成之前就遇到流结尾。”
ms.Close();
序列化:
public bool Serialization(Hashtable hashtable)
{
BinaryFormatter binaryFormatter = new BinaryFormatter();
System.IO.MemoryStream ms = new System.IO.MemoryStream();
binaryFormatter.Serialize(ms, hashtable);//内存流二级制序列化
ms.Position = 0;
byte[] b = new Byte[ms.Length];
ms.Read(b, 0, b.Length);
bool flag = new Product().ss(b);
ms.Close();
return flag; }下面是反序列化:
byte[] b = new Product().returnSeirazation();//数据库返回
System.IO.MemoryStream ms = new System.IO.MemoryStream(b);
BinaryFormatter binaryFormatter = new BinaryFormatter();
ms.Position = 0;
Items =(Hashtable)binaryFormatter.Deserialize(ms);//报错 在分析完成之前就遇到流结尾。”
ms.Close();
解决方案 »
- 急!关于SQL循环排序的效率问题
- Ext.net的问题,出鬼了,求大神帮忙
- 初学者的问题,有事没事请大家来看看,谢谢!
- 高手们帮我比较一下这两个控件在项目开发使用的效果
- 连接Oracle的问题,连接上了,但是数据填充时候总提示"ORA-12154: TNS: 无法处理服务名"错误
- 帮忙写一个sql语句,好像难度蛮大,高手进来挑战一下自我
- 分析器错误信息: 找不到文件或程序集名称“AspNetMMCExt”,或找不到它的一个依赖项。请问怎么解决?
- 关于类别名添加列的问题??
- 求救!装了VS.net后新建项目时它显示“VC软件包不可用或未注册”
- Response.write 屬於哪個命名空間?
- 关于discuz!nt整合
- 如何截取HTML源文件指定标签的内容?
/// 序列化发送消息
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public static byte[] SerializeBinary(object request)
{
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter serializer =
new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
System.IO.MemoryStream memStream = new System.IO.MemoryStream();
serializer.Serialize(memStream, request); //byte[] b = memStream.GetBuffer();
byte[] b = memStream.ToArray();
memStream.Close();
return b;
} /// <summary>
/// 反序列化接收消息
/// </summary>
/// <param name="buf"></param>
/// <returns></returns>
public static object DeserializeBinary(byte[] buf)
{
if (buf == null || buf.Length == 0) return null;
System.IO.MemoryStream memStream = new System.IO.MemoryStream();
memStream.Write(buf, 0, buf.Length);
memStream.Position = 0;
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter deserializer =
new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
object newobj = deserializer.Deserialize(memStream);
memStream.Close();
return newobj;
}