System.DllNotFoundException trying to call functions on a .DLL

I’m using .NET 6.0 with C#, and I have to to call some functions on a .DLL (dowload from product’s SDK). If I run my project without Docker, on Windows using Visual Code, the code work smoothly, but if I tried to run on Docker with Linux container (Containerize a .NET app according to’s tutorial), the code throws an error when trying to execute the .DLL function like this
Unhandled exception. System.DllNotFoundException: Unable to load shared library ‘.\HCNetSDK.dll’ or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: lib./HCNetSDK.dll: cannot open shared object file: No such file or directory
Normally, the .DLL file in my pc located at Myapp\bin\Debug\net6.0
Thank you in advance.

Hello @kavin9587 ,

DLL files are very much specific to Windows OS. if I’m not wrong.

as per the error DLL files are not loaded/avaialble in the container.

could you please share your docker file?
and how are you running container docker run or compose?


After I built image from dockerfile according to this tutorial

I run container by “docker run [my image]”. I can deploy c# program into docker container by follow the tutorial, but It look like there is no the .dll file was add into the container, as the error say “No such file or directory”
I’m not sure, if it because the .dll file was not added or the .dll file was added but can not open

here is my docker file

FROM AS build-env

COPY . ./

RUN dotnet restore

RUN dotnet publish -c Release -o out

COPY --from=build-env /App/out .
ENTRYPOINT [“dotnet”, “DotNet.Docker.dll”]

I tried to reproduce from the tutorial , I can not reproduce the error.
Only I can see you are using a different SDK version than what is there in tutorial.

in the tutorial, it is FROM AS build-env

I belive it’s not an issue with docker but something to do with .NET build and publish.

below are few suggestions
can you please update SDK version
can you check if you have published properly using dotnet publish -c Release before creating docker image.
also can you do a ls -l in your dockerfile or inside container.

$ docker run --rm counter-image                
Counter: 1
Counter: 2
Counter: 3
Counter: 4
Counter: 5
Counter: 6
Counter: 7
Counter: 8
Counter: 9
^ZCounter: 10
Counter: 11
Counter: 12