Arraylist of custom classes inside My.Settings

前端 未结 2 1256
一个人的身影
一个人的身影 2021-01-17 01:38

I have a Visual Basic .Net 2.0 program. I\'m moving the settings from an older settings file, to an app.config program settings file. I\'m trying to do this as nicely as p

2条回答
  •  Happy的楠姐
    2021-01-17 02:04

    Debug + Exceptions, tick the Thrown box for CLR exceptions. You'll now see what is going wrong. There are several exceptions but the deal breaker is the second one, "The type ... was not expected".

    Attributes are required to tell the xml serializer what types are stored in an ArrayList. This is described in this MSDN Library page, "Serializing an ArrayList" section. Problem is, you cannot apply the required [XmlElement] attribute since the ArrayList instance is declared in auto-generated code. A generic List(Of T) doesn't have the same problem, but now you'll smack into a restriction in the setting designer, it doesn't support generic types.

    Well, a rock and a hard place here, you can't make this work. StringCollection is the distasteful alternative. Or ditch the idea of using Settings for this and just do it yourself with xml serialization. Or whatever else you prefer.

提交回复
热议问题