ThinkGeo.com    |     Documentation    |     Premium Support

Serialization problem when switching between cultures

Hi guys,

We are using MapSuite 10 for WinForms.

Recently we began working on preparing our application for use in languages other than English. The language I am working on is Portuguese. In my testing I noticed that if we serialize certain objects when the current culture is set to Portuguese (pt-BR), then deserialize when the current culture is set to English (en-US) the RectangleShape does not deserialize correctly.

I have attached a sample project. Run the project. It will start with the current culture set to pt-BR. Click the Serialize button (a few of the map’s properties are saved). Place a break point in sub TestDeserialization, then use the radio button to switch to English and click the Deserialize button. Examine the properties of the BoundingBox on the MapProperties object that got deserialized. Notice that they are wrong. The numbers are so large it is obvious that they are incorrect, they should be within the normal values for decimal defreees.

Please let me know what I have do do to fix this.

Thanks!

Steve
SerializationTest.zip (2.3 MB)

Thanks Steven,
I compared the result. Instead of using a full stop to indicate a decimal point, the Portuguese language requires a comma.

So if you serialize the object in the English environment. You need use the English environment to deserialize. We can not use English environment to load the portuguese environment created xml file.

Thanks

Frank

Frank,

Thanks for your response. I understand now why it’s not working. I examined the xml but just didn’t notice the commas instead of the decimal points. I will be careful how I use the GeoSerializer.

Having said that, I wouldn’t expect to have to worry about culture when I’m saving an unformatted double value. A non-formatted double should be the same no matter what culture you use, that’s why I was confused with this behavior. If I uses a .NET DataContractSerializer it works like I expect in either culture.

Thanks for your help!

Steve

Thanks Steven,
When you serialize the object. You can use
Thread.CurrentThread.CurrentCulture = New CultureInfo(“en-US”) to always save the xml to the English format. and set it back after the xml file save to the disk.

The same thing for the deserialize. Before do the deserialize. use Thread.CurrentThread.CurrentCulture = New CultureInfo(“en-US”) set the environment to English. after you get the object back. The set the environment back to original one.

Thanks

Frank