我想使用XML序列化序列化ReportDocument但是徒劳无功,这是我的代码:
public String serialiser (ReportDocument rd)
{
StringWriter sw= new StringWriter();
System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(ReportDocument));
xs.Serialize(sw, rd);
return sw.ToString();
}
NB:CrystalDecisions.CrystalReports.Engine.ReportDocument。
我收到以下错误:
An error occurred during the reflection of the type 'CrystalDecisions.CrystalReports.Engine.ReportDocument'.
我怎么能序列化它?!
答案 0 :(得分:1)
我的猜测是该类型未标记为可序列化。你尝试过二进制序列化吗?
public static byte[] SerializeToBytes<T>(T original)
{
byte[] results;
using (MemoryStream stream = new MemoryStream())
{
BinaryFormatter binaryFormatter = new BinaryFormatter();
binaryFormatter.Serialize(stream, original);
stream.Seek(0, SeekOrigin.Begin);
results = stream.ToArray();
}
return results;
}