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

Enum Deserializer Issue with BsonType.String

    • Type: Icon: Improvement Improvement
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.7.0
    • Component/s: BSON
    • Labels:

      In the source code of c# Driver v2.7,

      Unable to find source-code formatter for language: csharp. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      namespace MongoDB.Bson.Serialization.Serializers
      {
          public class EnumSerializer<TEnum> : StructSerializerBase<TEnum>, IRepresentationConfigurable<EnumSerializer<TEnum>> where TEnum : struct
          {
            ......
            public override TEnum Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)
            {
              var bsonReader = context.Reader;
      
              var bsonType = bsonReader.GetCurrentBsonType();
              switch (bsonType)
              {
                  ......
                  case BsonType.String: return (TEnum)Enum.Parse(typeof(TEnum), bsonReader.ReadString());
                  default:
                      throw CreateCannotDeserializeFromBsonTypeException(bsonType);
              }
            }
           ......
          }
      }
      

      In this method, the code

      Unable to find source-code formatter for language: csharp. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      case BsonType.String: return (TEnum)Enum.Parse(typeof(TEnum), bsonReader.ReadString());
      

      will throw an ArgumentException when the ReadString() returns a value that is not defined in the TEnum type.

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            sunyutj Sun Yu
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: