我目前正在修改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页面:
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)
任何想法?