帮我解决以下问题:
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; }
提前致谢。
答案 0 :(得分:1)
是的,你需要标记这可能有帮助的非可序列化对象:
编辑:进一步说明:
IFormatter formatter = new BinaryFormatter();
IFormatter formatter = new SimpleIniFormatter();
FileStream s = new FileStream(fileName, FileMode.Create);
formatter.Serialize(s, line);`
在此示例中,NonSerialized意味着BinaryFormatter将忽略任何标记为非序列化的事件。 用户上面的例子来玩。创建的文件有点可读。其中line是一些标记为可序列化的对象