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

Client cannot resolve serializer anymore when using IQueryable with base type

    XMLWordPrintableJSON

Details

    • Icon: Task Task
    • Resolution: Unresolved
    • Icon: Unknown Unknown
    • None
    • None
    • Linq

    Description

      I have a public class `Entity` and an entity that inherits from that called `MongoEntity`.

      The MongoEntity is an implementation detail of the repository, so it is used only internally and is not exposed outside.

      e.g. something like this:

       

      class Entity {}
      class MongoEntity : Entity {}
      public class Repository{
         private IMongoCollection<MongoEntity> collection;
         
         public IQueryable<Entity> Entities {
             get => collection.AsQueryable();
         }
      }
      

      Until 2.18.0 it works fine, but it breaks with 2.19.0:

      I get the following exception in my sample:

      System.ArgumentException: 'ValueType 'ConsoleApp4.Program+MongoEntity' of parameterSerializer does not match parameter type 'ConsoleApp4.Program+Entity'. (Parameter 'parameterSerializer')'

      In my real application I get the following error:

      System.InvalidCastException: 'Unable to cast object of type 'MongoDB.Bson.Serialization.BsonClassMapSerializer`1[Notifo.Identity.MongoDb.MongoDbUser]' to type 'MongoDB.Bson.Serialization.IBsonSerializer`1[Microsoft.AspNetCore.Identity.IdentityUser]'.'

      I was not able to reproduce this exception in my sample, but I guess it is the same root issue.

      My very little example is attached.

      Attachments

        1. ConsoleApp4.csproj
          0.3 kB
        2. Program.cs
          1 kB

        Activity

          People

            Unassigned Unassigned
            sebastian@squidex.io Sebastian Stehle
            Votes:
            4 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated: