MongoDB.Driver 2.17.1 with client ecryption in docker throws: "Unable to load shared library 'libdl' or one of its dependencies"

Hi

The issue

I get errors while debugging ASP.NET 6 app that uses MongoDriver with client encryption in Visual Studio 2022 using docker image.

aspnet:6.0 and sdk:6.0 images

With these images I get the following error:

Exception thrown: ‘System.DllNotFoundException’ in MongoDB.Libmongocrypt.dll: ‘Unable to load shared library ‘libdl’ or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: liblibdl: cannot open shared object file: No such file or directory’

I added LD_DEBUG environment variable. I cannot add attachments as I am a new user - attaching a link to google drive MongoDB issue in docker - Google Drive.

aspnet:6.0-alpine image

With the mcr.microsoft.com/dotnet/aspnet:6.0-alpine image I get other error:

‘System.IO.FileNotFoundException’ in MongoDB.Libmongocrypt.dll: ‘/app/bin/Debug/net6.0/runtimes/linux/native/libmongocrypt.so’

More context info:

  • NET 6.0
  • MongoDB.Driver 2.17.1
  • Base images that I tried
    • aspnet
      • mcr.microsoft.com/dotnet/aspnet:6.0
      • mcr.microsoft.com/dotnet/aspnet:6.0-alpine
    • SDK
      • mcr.microsoft.com/dotnet/sdk:6.0
  • Client encryption
    • Local KMS provider

Exception stack trace

 >   at MongoDB.Libmongocrypt.LibraryLoader.LinuxLibrary.dlopen(String filename, Int32 flags)
 >   at MongoDB.Libmongocrypt.LibraryLoader.LinuxLibrary..ctor(String path)
 >   at MongoDB.Libmongocrypt.LibraryLoader..ctor()
 >   at MongoDB.Libmongocrypt.Library.<>c.<.cctor>b__0_61()
 >   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
 >   at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
 >   at System.Lazy`1.CreateValue()
 >   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.Encryption.ClientEncryption..ctor(ClientEncryptionOptions clientEncryptionOptions)

Thanks.

Hey @Oleksii , thanks for your report.
I’ve created a ticket to investigate this issue https://jira.mongodb.org/browse/CSHARP-4363. Please follow this ticket for updates and further discussions.
Meanwhile, can you please check whether this folder " /app/bin/Debug/net6.0/runtimes/linux/native/libmongocrypt.so" contains libmongocrypt.so binary and if no what binaries are there?

1 Like

aspnet:6.0-alpine image issue

Yes, the libmongocrypt.so is present.

root@b566ee55750b:/app/bin/Debug/net6.0/runtimes/linux/native# ls -l
total 3332
-rwxrwxrwx 1 root root 1886064 Jul 29 20:51 libmongocrypt.so
-rwxrwxrwx 1 root root  134080 Jul 29 23:24 libsnappy64.so
-rwxrwxrwx 1 root root 1384960 Jul 29 23:24 libzstd.so

aspnet:6.0 image issue

I tried to find libdl.so lib:

root@b566ee55750b:/# ls -l /lib/x86_64-linux-gnu/ | grep libdl
-rw-r--r-- 1 root root   18688 Aug 26 21:32 libdl-2.31.so
lrwxrwxrwx 1 root root      13 Aug 26 21:32 libdl.so.2 -> libdl-2.31.so
root@b566ee55750b:/# find / -type f -name "*libdl*"
/lib/x86_64-linux-gnu/libdl-2.31.so

As a temporary workaround, we installed libc6-dev in the container (see an extract from the Dockerfile).

FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
RUN apt-get update
RUN apt-get install libc6-dev -y
...

Did not check the final image size.