Results 1 to 6 of 6

Thread: [RESOLVED] [2008] XMLSerializer type serialization issue

  1. #1

    Thread Starter
    Frenzied Member obi1kenobi's Avatar
    Join Date
    Aug 2007
    Posts
    1,091

    Resolved [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?
    Please rate helpful ppl's posts. It's the best 'thank you' you can give

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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.

  3. #3
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    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.
    My usual boring signature: Nothing

  4. #4

    Thread Starter
    Frenzied Member obi1kenobi's Avatar
    Join Date
    Aug 2007
    Posts
    1,091

    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.
    Please rate helpful ppl's posts. It's the best 'thank you' you can give

  5. #5
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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.

  6. #6

    Thread Starter
    Frenzied Member obi1kenobi's Avatar
    Join Date
    Aug 2007
    Posts
    1,091

    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
    Please rate helpful ppl's posts. It's the best 'thank you' you can give

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width