MongoDB Driver incompatible with .net 4.8?

I am developing an ADFS plugin that connects to Mongo via the MongoDB Driver. This requires the libraries to be installed in the GAC, and and ran into two issues:

First one, the official driver available in nuget is not signed. This can easily be resolved by searching for and running an unofficial unsigned build from nuget, which we have.

Second one - this where I’m stuck:
I am running this on Windows Server 2016 with .net 4.8 installed. When the plugin code calls the MongoDB Driver to make a connection - the following error is thrown:

Code Snippet:

_mongoClientSettings = MongoClientSettings.FromConnectionString($“mongodb+srv://{_DBEndPoint}/{_DBNameMFA}?authSource=$external&authMechanism=MONGODB-X509&retryWrites=true&w=majority”);

Exception:

DnsClient.DnsResponseException: Query 4162 => api-dev.xdqkf.mongodb.net IN TXT on 10.118.2.239:53 failed with an error. ---> System.IO.FileNotFoundException: Could not load file or assembly 'System.Buffers, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified.
   at DnsClient.Internal.PooledBytes..ctor(Int32 length)
   at DnsClient.DnsDatagramWriter..ctor()
   at DnsClient.DnsUdpMessageHandler.Query(IPEndPoint server, DnsRequestMessage request, TimeSpan timeout)
   at DnsClient.LookupClient.ResolveQuery(IReadOnlyList`1 servers, DnsQuerySettings settings, DnsMessageHandler handler, DnsRequestMessage request, LookupClientAudit audit)
   --- End of inner exception stack trace ---
   at DnsClient.LookupClient.ResolveQuery(IReadOnlyList`1 servers, DnsQuerySettings settings, DnsMessageHandler handler, DnsRequestMessage request, LookupClientAudit audit)
   at DnsClient.LookupClient.QueryInternal(DnsQuestion question, DnsQuerySettings queryOptions, IReadOnlyCollection`1 servers)
   at MongoDB.Driver.Core.Configuration.ConnectionString.Resolve(Boolean resolveHosts)
   at MongoDB.Driver.MongoUrl.Resolve(Boolean resolveHosts)
   at MongoDB.Driver.MongoClientSettings.FromUrl(MongoUrl url)

The MongoDB Driver is looking for System.Buffers 4.0.2.0, but the version installed is 4.0.3.0, and as it’s in the same .net major version (4.x), there doesn’t seem to be a way to have both versions side by side…

Today, I’m going to try to rebuild the driver from github - which might allow us to regartet the .net version its built on and also allow us to sign it ourselves.

Thanks,
Abraham

Dunno what the standard is for replying to one’s own messages - someone set me strait if needed.

Here’s the solution:

First - Additional context:
This is a GAC installed library to be used as a TOTP plugin for ADFS
As such all dependent libraries also need to be present in the GAC as well.

Windows Server 2016
.NET 4.8 installed
Unofficial (Signed) MongoDB Driver v2.12.2

In my Project References / Manage NuGet Packages, I downgraded System.Buffers to 4.4.0 (from 4.5.1). This allowed me to copy it to the GAC during installation along with any other dependencies.

Hi @Abraham_Dybvig,

Welcome to the MongoDB community! Replying to your own topics is fine … and definitely appreciated if you can share any solutions or workarounds to help others who might encounter a similar issue.

You can also mark your own comment (or any that is most helpful in a topic that you have started) as a Solution.

Regards,
Stennie