XMLSerialize Exception

前端 未结 2 1944
我寻月下人不归
我寻月下人不归 2021-01-18 10:43

I am serializing a class and I get the following exception:

You must implement a default accessor on System.Configuration.SettingsPropertyCollection b

相关标签:
2条回答
  • 2021-01-18 11:16

    you have to have a default constructor, that is, one that does not take any parameters, like so....

    class foo
    {
        public foo() {}
    }
    

    if the class you are trying to serialize does not have one, XMLSerializer throws that exception. If you are trying to serialize a built-in class, you are going to have to derive your own or create a wrapper class.

    0 讨论(0)
  • 2021-01-18 11:33

    "default accessor" is the special property that returns an object of the collection based on its index. for example:

    [Serializable()]
    public class IntList : ICollection {
    
        // Default Accessor Implementation
        public int this[int index] {
            get {
    
                return 0;
            }
            set { /* Do Nothing */ }
        }
    }
    

    Therefore unavailable to implement that in existing third-party class. Using xml serializing for ApplicationSettings is very bad idea, use Save(), Reload() and Reset() methods, or use your own not derived from ApplicationSettingsBase CustomConfiguration classes.

    0 讨论(0)
提交回复
热议问题