Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-285

Decimal serialization/deserialization should not be affected by locale

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Trivial - P5 Trivial - P5
    • 1.1
    • Affects Version/s: 1.1
    • Component/s: None
    • None
    • Environment:
      Windows 7, .NET 4, C# driver v1.1, environment setting for decimal separator is a comma ","

      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.
      at System.Number.StringToNumber(String str, NumberStyles options, ref NumberBuffer number, NumberFormatInfo info, Boolean parseDecimal)
      at System.Number.ParseDecimal(String value, NumberStyles options, NumberFormatInfo numfmt)
      at MongoDB.Bson.Serialization.Serializers.DecimalSerializer.Deserialize(BsonReader bsonReader, Type nominalType, IBsonSerializationOptions options) in C:\work\10gen\mongodb\mongo-csharp-driver\Bson\Serialization\Serializers\NetPrimitiveSerializers.cs: line 744
      at MongoDB.Bson.Serialization.Serializers.BsonBaseSerializer.Deserialize(BsonReader bsonReader, Type nominalType, Type actualType, IBsonSerializationOptions options) in C:\work\10gen\mongodb\mongo-csharp-driver\Bson\Serialization\Serializers\BsonBaseSerializer.cs: line 69
      at MongoDB.Bson.Serialization.BsonClassMapSerializer.DeserializeMember(BsonReader bsonReader, Object obj, BsonMemberMap memberMap) in C:\work\10gen\mongodb\mongo-csharp-driver\Bson\Serialization\BsonClassMapSerializer.cs: line 305
      at MongoDB.Bson.Serialization.BsonClassMapSerializer.Deserialize(BsonReader bsonReader, Type nominalType, Type actualType, IBsonSerializationOptions options) in C:\work\10gen\mongodb\mongo-csharp-driver\Bson\Serialization\BsonClassMapSerializer.cs: line 127
      at MongoDB.Bson.Serialization.BsonClassMapSerializer.Deserialize(BsonReader bsonReader, Type nominalType, IBsonSerializationOptions options) in C:\work\10gen\mongodb\mongo-csharp-driver\Bson\Serialization\BsonClassMapSerializer.cs: line 81
      at MongoDB.Bson.Serialization.BsonSerializer.Deserialize(BsonReader bsonReader, Type nominalType, IBsonSerializationOptions options) in C:\work\10gen\mongodb\mongo-csharp-driver\Bson\Serialization\BsonSerializer.cs: line 217
      at MongoDB.Driver.Internal.MongoReplyMessage`1.ReadFrom(BsonBuffer buffer, IBsonSerializationOptions serializationOptions) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Internal\MongoReplyMessage.cs: line 94
      at MongoDB.Driver.Internal.MongoConnection.ReceiveMessage(BsonBinaryReaderSettings readerSettings, IBsonSerializationOptions serializationOptions) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Internal\MongoConnection.cs: line 337
      at MongoDB.Driver.MongoCursorEnumerator`1.GetReply(MongoConnection connection, MongoRequestMessage message) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Core\MongoCursorEnumerator.cs: line 263
      at MongoDB.Driver.MongoCursorEnumerator`1.GetFirst() in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Core\MongoCursorEnumerator.cs: line 223
      at MongoDB.Driver.MongoCursorEnumerator`1.MoveNext() in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Core\MongoCursorEnumerator.cs: line 126
      at System.Linq.Enumerable.FirstOrDefault(IEnumerable`1 source)
      at MongoDB.Driver.MongoCollection.FindOneAs(IMongoQuery query) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Core\MongoCollection.cs: line 493
      at MongoDB.Driver.MongoCollection.FindOneByIdAs(BsonValue id) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Core\MongoCollection.cs: line 529
      at MongoDB.Driver.MongoCollection`1.FindOneById(BsonValue id) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Core\MongoCollection.cs: line 1462
      at Domain.Storage.MongoSession.Single(ObjectId id) in MongoSession.cs: line 81
      at WebApp.Test.Controllers.RatingControllerTest.Rate_RecalculatesRating() in RatingControllerTest.cs: line 131

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            antoineleclair Antoine Leclair
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: