[RESOLVED] [2008] XMLSerializer type serialization issue
I'm trying to serialize a user's preferences by means of an XMLSerializer. The preferences class contains Strings, Integers, Booleans and several Color structure variables. The serialization doesn't throw any errors, however the generated xml file has empty values only for the color variables.
I tried the following two declarations of the XMLSerializer object, neither workerd.
Code:
Dim xml As New Xml.Serialization.XmlSerializer(GetType(UsrPreferences), New System.Type() {GetType(Color)})
Dim xml As New Xml.Serialization.XmlSerializer(GetType(UsrPreferences), New Xml.Serialization.XmlRootAttribute("UsrPreferences"))
How can I fix this?
Re: [2008] XMLSerializer type serialization issue
Perhaps it isn't serializable or if it is, it isn't dealt with properly.
http://msdn.microsoft.com/en-us/library/ms731923.aspx
You can create, say, a 'wrapper' class which stores the RGB values and get your client app to convert the color back to a proper Color.
Re: [2008] XMLSerializer type serialization issue
Do you have to do XML? There are a variety of things that are not serializable with XML, as Mendhak suggested, though the color structure seems like it should be. If you aren't tied to XML serialization, binary serialization works on more types (including generics), and is easy to use.
Re: [2008] XMLSerializer type serialization issue
I know the limitations of XML serialization, but I've gone too far to abandon it now. Besides, I prefer XML over binary.
I've thought of using a wrapper however I'd prefer to use the Color structure as is and I would only consider it as a last resort.
EDIT: I just remembered what is causing this problem. Apparently, you cannot set the A, R, G and B properties of a color manually since they are ReadOnly. The XMLSerializer will only save non-ReadOnly properties and public fields. I guess the wrapper is the only way. I'm sorry I bothered you.
Re: [RESOLVED] [2008] XMLSerializer type serialization issue
You can't set it directly but you can use a method, the name of which is vague to me, called FromARgb which returns a Color.
Re: [RESOLVED] [2008] XMLSerializer type serialization issue
I know that but the XMLSerializer cannot use that method, it sets values directly. That's why it ignores all ReadOnly properties.
Btw, the ARGB part stands for Alpha-Red-Green-Blue, where Alpha is the opacity of the color. Have a look:
http://en.wikipedia.org/wiki/Alpha_compositing