我有一个 XML 文档,我想将它存储在会话中,因此在每次回发时我不需要再次从其物理路径加载它。我们正在使用状态服务器。
当我尝试将其存储在 Session 中时,出现错误:
异常详细信息:System.Runtime.Serialization.SerializationException:在程序集“System.Xml,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089”中键入“System.Xml.XmlDocument”未标记为可序列化。
我的代码是这样的:
string resumeSection = string.Empty;
resumeSection = resume.GetXMLSection(1)
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(resumeSection);
Session["USERXML"] = xmloc;
如何进行序列化?
当我遇到错误时, 无法序列化会话状态。在“StateServer”和“SQLServer”模式下,ASP.NET 将序列化会话状态对象,因此不允许不可序列化的对象或 MarshalByRef 对象。如果自定义会话状态存储在“自定义”模式下完成类似的序列化,则适用相同的限制。