gottscj/Hangfire.Mongo

Hangfire.Mongo is incompatible with the MongoDB.Driver LINQ3 provider

0xced opened this issue · 1 comments

0xced commented

The MongoDB.Driver version 2.19.0 changed the LINQ provider to the new (V3) provider.

This new LINQ3 provider is incompatible with Hangfire.Mongo. I have filed bug CSHARP-4505 on the MongoDB.Driver JIRA project with reproduction sample code.

In the meantime it's possible to switch back to the V2 provider as documented in the release notes.

var connectionString = "mongodb://localhost";
var clientSettings = MongoClientSettings.FromConnectionString(connectionString);
clientSettings.LinqProvider = LinqProvider.V2;
var client = new MongoClient(clientSettings);

Temporary fix:

var connection = "....";
            var mongoUrlBuilder = new MongoUrlBuilder(connection);

            var clientSettings = MongoClientSettings.FromConnectionString(connection);
            clientSettings.LinqProvider = LinqProvider.V2; //https://github.com/mongodb/mongo-csharp-driver/releases/tag/v2.19.0
            var mongoClient = new MongoClient(clientSettings);

            services.AddHangfire(configuration => configuration
                .SetDataCompatibilityLevel(CompatibilityLevel.Version_170)
                .UseSimpleAssemblyNameTypeSerializer()
                .UseRecommendedSerializerSettings()
                .UseMongoStorage(mongoClient, mongoUrlBuilder.DatabaseName, new MongoStorageOptions
                {
                    MigrationOptions = new MongoMigrationOptions
                    {
                        ...
                    }
                })
            );