首页 文章

RuntimeResourceManager中的序列化问题

提问于
浏览
1

帮我解决以下问题:

Type 'System.Resources.RuntimeResourceSet' in Assembly 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable.

示例代码:

[Serializable]
    public class clsModelClass
    {
        private List _obj1 = new List();
        private List _obj2 = new List();
        public System.Resources.ResourceManager ResourceManager { get; set; }

        public string Property1 { get; set; }
        public long Property2 { get; set; }
        public string Property3 { get; set; }
    }

[Serializable]
    public class clsTestClass
    {
        public static string staticObj1 = "staticObj1";
        public static string staticObj2 = "staticObj2";
        public static string staticObj3 = "staticObj3";
    }

是因为:

public System.Resources.ResourceManager ResourceManager { get; set; }

因为ResourceManager类没有序列化 . 我应该使用[nonSerialize]吗?

[nonSerialize]
public System.Resources.ResourceManager ResourceManager { get; set; }

提前致谢 .

1 回答

  • 1

    是的,您需要标记不可序列化的对象,这可能会有所帮助:

    NonSerializedAttribute

    编辑:进一步说明:

    IFormatter formatter = new BinaryFormatter();             
    IFormatter formatter = new SimpleIniFormatter();
    FileStream s = new FileStream(fileName, FileMode.Create);
    formatter.Serialize(s, line);`
    

    在这个例子非序列化意味着该BinaryFormatter的会忽略无论发生什么事被标记为非序列化 . 用户上面的例子来玩 . 创建的文件有点可读 . 其中line是一些标记为可序列化的Object

相关问题