我目前正在修改 ASP.NET (3.5) 应用程序以在 SQLServer SessionState
模式下运行。在现有代码中,我们有一个序列化的数据集,该数据集当前
使用 C# 存储在 Session 中。我有一个属性,用于提取此序列化数据集并将其加载到 XmlDataDocument 中。我的财产是这样的“东西”:
public abstract class TransCommand
{
public static XmlDataDocument TransDoc
{
get
{
XmlDataDocument doc = null;
if (Session["DataSetStore"] != null)
{
DataSet tds3 = new DataSet();
MemoryStream tms3 = new MemoryStream(HttpContext.Current.Session["DataSetStore"] as byte[]);
doc = new XmlDataDocument();
doc.LoadXml(System.Text.Encoding.UTF8.GetString(tms3.ToArray()));
}
return doc;
}
set
{
Session["DataSetStore"] = System.Text.Encoding.UTF8.GetBytes(value.OuterXml);
}
}
这很好用,除非我尝试将 XmlNode 附加到从此
TransDoc 方法创建的节点上。
public class AddChildren
{
XmlDataDocument doc = TransactionCommand.TransactionDoc;
doc.DataSet.EnforceConstraints = false;
XmlNode dataNode = doc.SelectSingleNode("//WebServiceResponse/Data");
......
ArrayList lstNewInfants = new ArrayList();
1stNewInfants.add(newInfants); //Adding new Infants XmlNodes into an arraylist.
foreach (XmlNode nodInfant in lstNewInfants)
{
dataNode.AppendChild(nodInfant);
}
doc.DataSet.EnforceConstraints = true;
TransactionCommand.TransactionDoc = doc; //Adds the modified doc back into the session
追加此节点后,我在遇到下一页aspx页面的Databind后收到以下异常:
Error Message:Type 'System.Xml.XmlBoundElement' in Assembly 'System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable.
Stack Trace: at System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers(RuntimeType type)
at System.Runtime.Serialization.FormatterServices.GetSerializableMembers(Type type, StreamingContext context)
at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitMemberInfo()
at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter)
at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.Serialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter)
at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck)
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck)
at System.Web.Util.AltSerialization.WriteValueToStream(Object value, BinaryWriter writer)
有任何想法吗?