I have problems with serializing enum values.
Here is the code:
[System.Xml.Serialization.XmlRootAttribute(Namespace = \"\", IsNullable = false)]
pub
Try putting [Flags] attribute on the enum.
I found what was wrong. For every enum type
[System.Xml.Serialization.XmlAttributeAttribute()]
public REQUESTTypetype Type;
I got this:
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool TypeSpecified;
And in the code I should do this:
request.Type = REQUESTTypetype.One;
request.TypeSpecified = true;
It works fine now. I should have post them in my question but I did not pay attention to these "specified" members at all. Thanks for your replies.
Do you see the same problem when you set the type to "Two" or "Three"? Is it because "One" is the default value and so can be assumed? It might be some artifact of loading this into an XmlDocument and then saving it with your code that you've not shown (TestWriteXml).
This slightly modified version of your code (I'm writing to a StringBuilder and then ToString'ing it at the end)...
REQUEST request = new REQUEST();
request.ID = "1234";
request.Type = REQUESTTypetype.One;
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
XmlSerializer xs = new XmlSerializer(typeof(REQUEST));
xs.Serialize(sw, request);
Console.WriteLine(sb.ToString());
... using the EXACT same types as you mention above appears to work fine. I get this at the console...
<?xml version="1.0" encoding="utf-16"?>
<REQUEST xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http:/
/www.w3.org/2001/XMLSchema" ID="1234" Type="One" />
I didn't change the definition of REQUEST or the enum REQUESTTypetype.
You can use the Xml.Serialization.XmlEnum attribute (see here) to decorate the values of the enum.
There is a blog post by Kurt Claeys here that might help as well.
In your actual code, is the member:
?
All 3 must be true. For nested types, every parent type in the nesting must be public.
Additional things that would exclude it: