大家帮忙看看,报错“在分析完成之前就遇到流结尾。”
序列化:
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();
解决方案 »
- 如何判断 文本框里面的值 是否改动了
- xp系統,用iis發布asp網站問題!急
- 在线急待:datagrid的模板列如何实现绑定不用的图片??
- 求一个项目的源代码
- 在线对CSS文件操作系统设计思路
- CMS二次开发的教程那里有?
- 重复贴图的问题
- 一个关于提取数据库中null值的问题,请教!!
- 选择DropDownList控件的SlectedItem值时(不刷新当前页)如何从另一个DropDownList控件得到它的SelectidItems值?(望高手指点,万分感谢
- 怎么在安装程序的自定义操作程序中取得CustomActionData属性?
- 关于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;
}