Libmongocrypt failing on C# on M1 Mac

I’m trying to use CSFLE on a M1 Mac with C#. I am on the v2.15.0 driver and starting up the project fails with the following error:

Unhandled exception. System.IO.FileNotFoundException: /Users/Adam/test-dot/Apps/Template/bin/Debug/net6.0/runtimes/osx/native/libmongocrypt.dylib
   at MongoDB.Libmongocrypt.LibraryLoader.DarwinLibraryLoader..ctor(String path)
   at MongoDB.Libmongocrypt.LibraryLoader..ctor()
   at MongoDB.Libmongocrypt.Library.<>c.<.cctor>b__0_50()
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
   at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.get_Value()
   at MongoDB.Libmongocrypt.Library.<>c.<.cctor>b__0_1()
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
   at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
   at System.Lazy`1.CreateValue()
   at MongoDB.Libmongocrypt.CryptClientFactory.Create(CryptOptions options)
   at MongoDB.Driver.Core.Clusters.CryptClientCreator.CreateCryptClient(CryptOptions options)
   at MongoDB.Driver.Core.Clusters.CryptClientCreator.CreateCryptClient(IReadOnlyDictionary`2 kmsProviders, IReadOnlyDictionary`2 schemaMap)
   at MongoDB.Driver.Encryption.ClientEncryption..ctor(ClientEncryptionOptions clientEncryptionOptions)
   at DotNet.Common.MongoEncryption.MongoEncryptionServiceExtensions.AddMongoDbEncryption(IServiceCollection services)

It works fine in rosetta but I’m having issues debugging my app with Rider / VS / VSCode. How can I resolve this?

This work is scheduled, but not implemented yet, see this ticket https://jira.mongodb.org/browse/CSHARP-4016 for details

1 Like

Thanks for the update. Is there a work around in the meantime?

Hi, @Vishal_Rastogi1,

CSHARP-4016 will package a universal binary for libmongocrypt.dylib supporting x64 Intel and ARM64 M1. At the moment, libmongocrypt.dylib only support x64 Intel architectures. To work around this at the moment, you can run your application on .NET 5 (which executes through Rosetta 2 on M1) or compile your .NET 6 app for x64-only (once again running your .NET app through Rosetta 2).

Sincerely,
James

1 Like