I have a strange problem with XMLSerializer.Serialize - when serializing an object with a valid enum valie (e.g. Item911), I receive an InvalidOperationException with error message "There was an error generating the XML document."
But: The enum value seems valid, it is in the generated enum from the contract (enum has been created automatically via xsd.exe)
The stack trace points me to the call of System.Xml.Serialization.XmlSerializer.Serialize, the rest is generated code from microsoft:
<Exception
Type=System.InvalidOperationException
Message=Instance validation error: '911' is not a valid value for YYY.
Source=Microsoft.GeneratedCode>
<StackTrace><![CDATA[
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterSonstigeFolgeeingabe.Write61_DienststelleMenge(DienststelleMenge v)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterSonstigeFolgeeingabe.Write65_Aktenzeichen(String n, String ns, Aktenzeichen o, Boolean isNullable, Boolean needType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterSonstigeFolgeeingabe.Write140_SonstigeFolgeeingabe(String n, String ns, SonstigeFolgeeingabe o, Boolean isNullable, Boolean needType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterSonstigeFolgeeingabe.Write141_SonstigeFolgeeingabe(Object o)
]]>
</StackTrace>
</Exception>
It only occurs in production (release compiled), when I try to debug it the code (even with Data where it fails in production), it works.
Additional context:
- the data is for a payload of a webservice call
- the classes are generated via xsd.exe from xsd-files and not manipulated
- I wasn't able to reproduce the bug
I tried to reproduce the bug locally and at the customer (working in a debug environment with mocked webservices), but I wasn't able to reproduce the bug.