Exit 145 when loading Driver dll using NET Core 3.1 in Docker container

Docker is returning exit code 145, which implies that .NET Core could not load the MongoDB Driver (2.11)

I am using the driver from NuGet.

Any idea on what is missing?

Hi @Jose_Gonzalez!

Do you mind sharing the docker file you are trying to run so that we can see a bit more context on the image you are trying to build?

That exit code could mean several things, so it will be helpful to see the full picture!


1 Like

For the record:

Environment - .NET Core 3.1 in a Docker Container with Ubuntu 18 as the OS.

Error: When the MongoDb driver was loaded as part of a dynamically loaded DLL, the container would exit with error code 145.

Solution: DLL must be loaded using Application Context (see https://docs.microsoft.com/en-us/dotnet/core/dependency-loading/understanding-assemblyloadcontext) and not Assembly.LoadFile (see https://docs.microsoft.com/en-us/dotnet/api/system.reflection.assembly.loadfile?view=netcore-3.1).

The proper call is:


And not:


NOTE: I do not know if the issue is limited to Ubuntu 18 or also happens with other Linux versions. Does not happen when running in MS Windows 10.

This issue may also occur to other DLLs which have been created as part of a process outside the compilation step that is generating the parent executable, not just MongoDb… Also it is an issue only with .NET Core.

1 Like


Glad to know that you were able to resolve it.

And thank you for coming back to share your solution. I’m sure it will help others who may come across the same issue you did!


This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.