2

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?

MiguelM
  • 197
  • 2
  • 9

1 Answers1

2

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 float or another data type that holds decimals, XmlSerializer should 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.

C.Evenhuis
  • 25,996
  • 2
  • 58
  • 72
  • Thanks for pointing me in the right direction. The "deserialization" part was actually some custom code reading values from a text file. There were some `.ToDecimal()` there, I added `InvariantCulture` and that seems to solve the problem in a quick test. – MiguelM Jan 03 '11 at 16:27