【问题标题】:Session state server saying extended class no serializable会话状态服务器说扩展类不可序列化
【发布时间】:2012-12-06 19:02:10
【问题描述】:

我在会话状态中存储一个对象(使用本地会话状态服务器),类 def 是:

 [Serializable]
 public class ExtendedOAuth2Parameters : OAuth2Parameters

但服务仍在报告:

Unable to serialize the session state. In 'StateServer' and 'SQLServer' mode, ASP.NET will serialize the session state objects, and as a result non-serializable objects or MarshalByRef objects are not permitted.

[SerializationException: Type 'Google.GData.Client.OAuth2Parameters' in Assembly 'Google.GData.Client, Version=2.1.0.0, Culture=neutral, PublicKeyToken=04a59ca9b0273830' is not marked as serializable.]

如何解决?

【问题讨论】:

    标签: asp.net serialization session-state


    【解决方案1】:

    根据错误消息,看起来基类 (Google.GData.Client.OAuth2Parameters) 是不可序列化的,因此即使您使用 Serializable 属性标记了您的类,完整的类层次结构也不是。

    您需要使用本身可序列化的 bass 类,或者如果您有权访问代码(可能没有?),则将 Google.GData.Client.OAuth2Parameters 类设为可序列化。

    请记住,“可序列化”取决于任何给定类的完整类型树 - 即所有基类和成员类也需要可序列化,以使封闭类真正可序列化。

    【讨论】:

    • 是的,这些是我的怀疑,此后我一直在重构我的代码,以将其他内容持久保存到会话中,并将其水合到检索时的第 3 方类
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-08-03
    • 2011-11-03
    • 2011-09-01
    • 1970-01-01
    • 2015-06-17
    • 2011-06-09
    • 1970-01-01
    相关资源
    最近更新 更多