[CSHARP-4200] MongoDB.Driver connections fail in .net core 3.1 Azure Functions (v3) Created: 07/Jun/22  Updated: 28/Oct/23  Resolved: 14/Jun/22

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: None
Fix Version/s: 2.16.1

Type: Bug Priority: Unknown
Reporter: Mark Sundquist Assignee: Boris Dogadov
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

Summary

When attempting to use any version of MongoDB.Driver newer than 2.14.1 in a .net core 3.1 Azure Function (v3), the following exception is thrown:

MongoDB.Driver.Core: The type initializer for 'MongoDB.Driver.Core.Misc.DnsClientWrapper' threw an exception. DnsClient: Error resolving name servers. DnsClient: Could not load file or assembly 'Microsoft.Win32.Registry, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.

This occurs regardless of whether the correct version of Microsoft.Win32.Registry is installed.  

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

v2.15.0 and higher

How to Reproduce

Create a C# .net core 3.1 Azure http trigger Function, add MongoDB.Driver v2.15.0+ and attempt to connect to a MongoDB instance.

Additional Background

The error occurs regardless of whether dependency injection is used in the function



 Comments   
Comment by Githook User [ 21/Jun/22 ]

Author:

{'name': 'BorisDog', 'email': 'BorisDog@users.noreply.github.com', 'username': 'BorisDog'}

Message: CSHARP-4200: DnsClient version update (#818)

MongoDB.Driver connections fail in .net core 3.1 Azure Functions (v3)
Branch: v2.16.x
https://github.com/mongodb/mongo-csharp-driver/commit/31bd36fdd280787635c0fd5c96e1e8b128379707

Comment by Githook User [ 14/Jun/22 ]

Author:

{'name': 'BorisDog', 'email': 'BorisDog@users.noreply.github.com', 'username': 'BorisDog'}

Message: CSHARP-4200: DnsClient version update (#818)

MongoDB.Driver connections fail in .net core 3.1 Azure Functions (v3)
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/66662c85aee7a7f0d3b9c134813bff0fbb37b276

Comment by Boris Dogadov [ 08/Jun/22 ]

Hi msundquist@onebridge.tech 

Looks like the underlying issue is probability due to some .net core compatibility in Azure Functions, as DnsClient.NET is not able to use Microsoft.Win32.Registry assembly. We submitted a new issue to track that.
A possible workaround would be upgrading to Azure Functions (V4), .net 6 (seems that this is fixed in that version). We will update of any additional workarounds if found.

Please follow this ticket for further updates.

Comment by Boris Dogadov [ 07/Jun/22 ]

Hi Mark,
Thank you the bug report, we are looking into it.

Generated at Wed Feb 07 21:47:31 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.