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

Enums with e.g. uint underlyings fail to serialized

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 2.12.0
    • Affects Version/s: 2.4.4
    • Component/s: Serialization
    • Labels:
      None

      As per this SO issue:

      https://stackoverflow.com/questions/47781059/c-sharp-mongodb-tries-to-convert-enumuint32-to-int32-and-crashes

      Easy to reproduce in EnumSerializerUInt32Tests.cs by switching from

              private enum E : uint
              {
                  A = 1,
                  B = 2
              }
      

      to

              private enum E : uint
              {
                  A = uint.MaxValue,
                  B = 2
              }
      

      and running the contained tests.

      Result: Exception: "Value was either too large or too small for an Int32."

      The problem here is in the EnumSerializer which attempts a Convert.ToInt32 for a Uint32 and a Convert.ToInt64 for a Uint64.

            Assignee:
            boris.dogadov@mongodb.com Boris Dogadov
            Reporter:
            daniel.hegener@gmx.net Daniel Hegener
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: