ce上,反序列化。
public static object ByteAToObject(byte[] binaryData)
{
MemoryStream ms = null;
object obj = null;
try
{
// 反序列化
ms = new MemoryStream(binaryData);
ms.Position = 0;
CompactFormatter.CompactFormatter ser = new CompactFormatter.CompactFormatter();
obj = ser.Deserialize(ms);
}
catch (Exception e)
{
MessageBox.Show(e.ToString(), "错误");
}
finally
{
ms.Close();
}
return obj;
} 主机上序列化:
public static byte[] ObjectToByteA(object obj)
{
using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
{
try
{
CompactFormatter.CompactFormatter ser = new CompactFormatter.CompactFormatter();
ser.Serialize(ms,obj); //这里出错。。
byte[] buffer = ms.ToArray();
return buffer;
}
catch (Exception e)
{
MessageBox.Show(e.ToString(), "错误");
}
finally
{
ms.Close();
}
return null;
}
} 错误提示:Message = "Unable to serialize System.Data.DataSet type, it's not ed with Serializable attribute and no surrogate or overriders are registered for it"
请教各位达人了!
public static object ByteAToObject(byte[] binaryData)
{
MemoryStream ms = null;
object obj = null;
try
{
// 反序列化
ms = new MemoryStream(binaryData);
ms.Position = 0;
CompactFormatter.CompactFormatter ser = new CompactFormatter.CompactFormatter();
obj = ser.Deserialize(ms);
}
catch (Exception e)
{
MessageBox.Show(e.ToString(), "错误");
}
finally
{
ms.Close();
}
return obj;
} 主机上序列化:
public static byte[] ObjectToByteA(object obj)
{
using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
{
try
{
CompactFormatter.CompactFormatter ser = new CompactFormatter.CompactFormatter();
ser.Serialize(ms,obj); //这里出错。。
byte[] buffer = ms.ToArray();
return buffer;
}
catch (Exception e)
{
MessageBox.Show(e.ToString(), "错误");
}
finally
{
ms.Close();
}
return null;
}
} 错误提示:Message = "Unable to serialize System.Data.DataSet type, it's not ed with Serializable attribute and no surrogate or overriders are registered for it"
请教各位达人了!
换个问题。
c# winCE上怎么读INI文件或者文本文件。