TurnerSoftware / MongoFramework

An "Entity Framework"-like interface for MongoDB
MIT License
392 stars 35 forks source link

Trying to access MongoDbSet<> - Object reference not set to an instance of an object. #338

Closed leftbrasil closed 1 year ago

leftbrasil commented 1 year ago

image

Got this error using both, main and fluent-mapping branches. Could you give me a tip on what's happening?

Declared my context:

public class MensagensDbContext : MongoDbContext
    {
        public MensagensDbContext(IMongoDbConnection connection) : base(connection)
        {
        }
        public MongoDbSet<Mensagem> Mensagens { get; set; }
        public MongoDbSet<MediaMessage> MediaMessages { get; set; }
    }

Dependency injection:

builder.Services.AddTransient<IMongoDbConnection>(
    s => MongoDbConnection.FromConnectionString(mongocon)
    );
builder.Services.AddTransient<MensagensDbContext>();
leftbrasil commented 1 year ago

In this case, providerType.GetMethod("Translate") returns null and providerType.GetMethods() doesn't show any "Translate" method

leftbrasil commented 1 year ago

The problem is the MongoDb.Driver. I believe that the version 2.19.0 renamed the "Translate" method to "CreateQuery". Rolled back to version 2.18.0 of the driver and it works perfectly fine.

Turnerj commented 1 year ago

Hey @leftbrasil - thanks for raising this issue! Yep, that looks like an integration bug with MongoFramework and the MongoDB driver. I'm planning to do another release soon with some major changes, I'll try and get in a fix for driver 2.19.0.

Turnerj commented 1 year ago

I've released v0.28.0 of MongoFramework which addresses the problem with the 2.19.0 version of the driver.