Wimdows.NET

Wim's .NET blog

XmlSerializer - some (enum) field not getting serialized...?

Here's the scenario. I'm serializing a particular object, which contains other objects as properties. I have this particular enum type that won't get included in the serialized XML.

For illustration - I'll simplify the class (which is a property of the main class being serialized); it looks as follows:

public class Contact
{
  public ContactRoleType ContactRole;
  public string ContactID;
  // ....and some more fields...
}


The ContactRoleType is a normal enum. All fields are serialized, except the enum field ContactRole. Strange thing is, when I rename the member field ContactRole, it does get serialized.

I have actually used 
Chris Sells' excellent tool XmlSerializerPreCompiler , and all the types can be serialized without any problem.

All comments and ideas are welcomed!

Thanks!

Posted: Apr 14 2004, 01:34 PM by Wim | with 5 comment(s)
Filed under:

Comments

Dave said:

Thanks a lot for posting about this tool!
# May 14, 2004 5:15 PM

wuxsh said:

I have the same problem .I user Framework 2.0!

# August 14, 2007 5:47 AM

Steve Kendrick said:

Hey I have this problem too... Funny thing is, I believe it's in the same code you did! Get in touch buddy!

# September 27, 2007 11:09 AM

Esdee said:

i had a similar problem with an enum property, turned out the property had to have setter as well as getter - my initial implementation required only a getter for encapsulation or whatever... :)

check out how i solved it at my blog esdeeblog.blogspot.com

# February 19, 2008 1:27 PM

Einstein said:

Hey, i too have this problem and when I rename it works. But in my case u cannot rename it as we generated it with an XSD which we got from a client and they expect the same attribute name as that of the enum. Is there any other solution other than renaming the property name ??

# November 4, 2008 11:29 PM
Leave a Comment

(required) 

(required) 

(optional)

(required)