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

InvalidCastException on converting underlying type to enum

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Blocker - P1 Blocker - P1
    • 2.21.0
    • Affects Version/s: 2.19.0, 2.19.1, 2.19.2, 2.20.0
    • Component/s: None
    • None
    • Fully Compatible
    • Not Needed
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      Summary

      Unable to cast object of type 'MongoDB.Bson.Serialization.Serializers.Int32Serializer' to type 'MongoDB.Driver.Linq.Linq3Implementation.Serializers.IEnumUnderlyingTypeSerializer

      Please provide the version of the driver. If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster).

      Please refer the following code where I receive error while using an ENUM value (VehicleType)vehicle.Type with mongodb c# driver version 2.19 & above

      How to Reproduce

      cehcileInfo = await (from vehicle in _mongodb.Vehicles.AsQueryable()

                                                                                                                                                      where vehicle.Id == vehicleId

                                                                                                                                                      select new VehicleMetaData()

                                                                                                                                                     

      {                                                                                                                                                                 Id = vehicle.Id,                                                                                                                                                                 CustomerId = vehicle.CustomerId,                                                                                                                                                                 Name = vehicle.Name,                                                                                                                                                                 Type = (VehicleType)vehicle.Type,                                                                                                                                                 }

      ).FirstOrDefaultAsync();

      Additional Background

      Please provide any additional background information that may be helpful in diagnosing the bug.

            Assignee:
            oleksandr.poliakov@mongodb.com Oleksandr Poliakov
            Reporter:
            ganeshmukeshraj1999@gmail.com Ganeshraj K
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: