I’m using XmlSerializer with classes created from a xsd using xsd.exe. It has worked fine for months.
Now I’m receiving reports that in some cases the created xml file has all decimals serialized without a decimal point, e.g. 123.45 is serialized as 12345.
I haven’t been able to reproduce the problem, but I’m suspecting it may be related to localization.
This is my first C# project, so I may be overlooking something basic.
Could localization cause this problem?
How can I make the serialization process locale independent?
Any idea of something else that could cause this problem?
In some countries they use a comma as decimal separator, and the dot to separate thousands, so your hunch could be true. If you’re using a
floator another data type that holds decimals,XmlSerializershould not in any case throw away the decimals. However if in such a country you read The Xml without specifying a culture, it might ignore the dot.So Xml serialized in one country and deserialized in another country would cause problems if you don’t specify something like
InvariantCulture.