无法序列化会话状态... [更新!] [英] Unable to serialize the session state... [Updated!]

查看:396
本文介绍了无法序列化会话状态... [更新!]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想存储在会话中的某些对象(其使用的StateServer),但我得到的错误System.Web.HttpException:无法序列化会话状态在的StateServer'和'的SQLServer模式

I am trying to store some objects in the session (which is using a StateServer), but I am getting the error "System.Web.HttpException: Unable to serialize the session state. In 'StateServer' and 'SQLServer' mode"

我认识的错误消息意味着什么,但我不能工作了,为什么。所有我使用的类被标记为可序列化,我能够序列化和反序列化对象的使用和XML:

I know what the error message means, but I can't work out why. All of the classes I am using are marked as Serializable, and I am able to Serialize and Deserialize the object to and from XML using:

System.IO.StringReader stringReader = new System.IO.StringReader(xml);
System.Xml.XmlTextReader xmlTextReader = new System.Xml.XmlTextReader(stringReader);
System.Xml.Serialization.XmlSerializer xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(Parts));
Parts obj = ((Parts)(xmlSerializer.Deserialize(xmlTextReader)));

这工作的,将系列化以及使用:

This works, and will Serialize as well using:

System.Xml.Serialization.XmlSerializer xmlSerializer = new System.Xml.Serialization.XmlSerializer(this.GetType());
System.IO.MemoryStream memoryStream = new System.IO.MemoryStream();
xmlSerializer.Serialize(memoryStream, this);
memoryStream.Seek(0, System.IO.SeekOrigin.Begin);
System.IO.StreamReader streamReader = new System.IO.StreamReader(memoryStream);
return streamReader.ReadToEnd();



但是,试图将其存储在会话时抛出的错误。

But the error is thrown when trying to store it in the Session.

有没有人有任何想法可能会导致此行为

Does anyone have any ideas what may be causing this behaviour?

编辑:

我刚刚发现这行导致错误(去掉一切,重新纳入吧)

I have just discovered that this line is causing the error (having removed everything and re-included it)

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("RecordReference", typeof(RecordReference), Form = System.Xml.Schema.XmlSchemaForm.Unqualified, Order = 0)]
[System.Xml.Serialization.XmlElementAttribute("PartContainer", typeof(PartContainer), Form = System.Xml.Schema.XmlSchemaForm.Unqualified, Order = 0)]
public object Item
{
    get
    {
        return this.itemField;
    }
    set
    {
        this.itemField = value;
    }
}

如果我把这个项目属性设置为新RecordReference(),则发生错误。如果为null,它的罚款。

If I set this "Item" property to "new RecordReference()", then the error occurs. If it is null, it's fine.

所以,现在的问题是,为什么不能的StateServer应付呢?序列化到XML时,它系列化精...

So now, the question is, why can't the StateServer cope with this? It serializes fine when serializing to XML...

修改...

键入System.Xml.XmlElement'在大会'的System.Xml,版本= 2.0.0.0,文化=中性公钥= b77a5c561934e089'未标记为可序列化。

Type 'System.Xml.XmlElement' in Assembly 'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable.

.....难道我们说,在C#中的XML对象不是序列?没有任何人想在这个疯狂的青草?

.....Are we saying that the Xml objects in C# aren't serializable?! Does anyone else think this verges on the insane?

推荐答案

所以,我已经找到了问题的答案,但我不高兴的。

So I have found the answer to the question, but I'm not happy about it.

基本上,一些我使用的是含有XMLElements和将XMLNode(他们使用SvcUtil工具自动生成)的类。无论出于何种原因,但它认为它需要它们。

Basically, some of the classes I'm using contain XMLElements and XMLNodes (they're automatically generated using svcutil). For whatever reason, but it thinks it needs them.

无论这些XML类是可序列化!我是唯一一个谁认为这是这些对象的完全失败?因此,要获得这组类到会话中,我已经得到了序列化他们到一个字符串,然后存储在会话,而这又是其序列。所以,我为了其序列为它被序列化.....!?

Neither of these XML classes are serializable!! Am I the only one who finds this to be a complete failing of these objects? So to get this set of classes into the session, I've got to serialize them down to a string, and then store that in the session, which is in turn serializing it. So I'm serializing it in order for it to be serialized.....!?

不知道我很高兴与,但那是原因我的问题。

Not sure I'm happy with that, but that was the cause of my problems.

这篇关于无法序列化会话状态... [更新!]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆