[CSHARP-285] Decimal serialization/deserialization should not be affected by locale Created: 26/Jul/11 Updated: 02/Apr/15 Resolved: 26/Jul/11 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | None |
| Affects Version/s: | 1.1 |
| Fix Version/s: | 1.1 |
| Type: | Bug | Priority: | Trivial - P5 |
| Reporter: | Antoine Leclair | Assignee: | Robert Stam |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Windows 7, .NET 4, C# driver v1.1, environment setting for decimal separator is a comma "," |
||
| Description |
|
The decimal separator in my regional settings is a comma ",". When I store decimal variables, the driver saves them as string (which seems to be by design). But the problem is that the string contains a comma for the separator and it throws an exception when the object is deserialized. For example, the number 3.25 appears as the string "3,25" in the database and won't deserialize. Also, I tried to add [BsonRepresentation(BsonType.Double)], but the representation in the database is still a string containing a comma. This may be another bug by itself. Here's the stack trace of one of my unit test failing: System.FormatException : Input string was not in a correct format. |
| Comments |
| Comment by Robert Stam [ 26/Jul/11 ] |
|
No problem. I'm happy to check it out. Could easily have been a real problem. Let me know if after further review you find anything else you want me to look at. |
| Comment by Antoine Leclair [ 26/Jul/11 ] |
|
I tested your code, it works fine. I am terribly sorry, it must be some kind of abstraction layer we use that caused the bug. |
| Comment by Robert Stam [ 26/Jul/11 ] |
|
I can't reproduce this. When Decimal is converted to a string it uses XmlConvert.ToString which is not culture sensitive. String is the default representation for Decimal because BSON has no equivalent data type. Here's my test program: And here's the output (note that the string representation of Decimal is using a "." even though the CurrentCulture was set to German): { "_id" : ObjectId("4e2ede14e447ad2bd0ed5d78"), "Culture" : "German (Germany)", "Decimal" : "1.23" }Press Enter to continue Changing the representation in your code does not affect existing data, so any strings with commas already in the database are there to stay and will have to be either removed or fixed using some other process. |