4

I have .net core console application which calls a cpp dll methods using DllImport. this cpp dll is compiled in windows and is not compatible with linux. So we decided to dockerize this console application in a Windows Container docker image. DllImport doesnt works there it say's

'Unable to load DLL 'Some.dll' or one it's dependencies ...'

We entered to the docker container using this command:

docker exec -it [ImageName] cmd 
app.exe --PrintCurrentWorkingDirectory

So we can see the Environment.CurrentDirectory on our application in container environment. It was Ok, and our DLL file was placed in the same path that our application was there.

Technical Information:

  • Base Image

    • Type: Windows Server Core
    • Call: FROM mcr.microsoft.com/windows/servercore:ltsc2019
  • Our DLL dependencies found using (dependency walker):

VCRUNTIME140.dll
MSVCP140.dll
KERNEL32.dll

  • Our docker file:
FROM mcr.microsoft.com/windows/servercore:ltsc2019 as runtime

SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]

ADD https://dot.net/v1/dotnet-install.ps1 C:/setup/dotnet-install.ps1

RUN C:/setup/dotnet-install.ps1 -Runtime aspnetcore -Channel 5.0 -Version latest -InstallDir c:\dotnet

ENV DOTNET_ROOT=c:/dotnet

ADD https://aka.ms/vs/16/release/vc_redist.x64.exe C:/setup/vc_redist.x64.exe

RUN C:/setup/vc_redist.x64.exe /install /quiet /norestart

WORKDIR /app

copy . /app

ENTRYPOINT ["dotnet", "app.dll"]

C# DllImport call:

    [DllImport(@"Stitching.dll", CallingConvention = CallingConvention.Cdecl)]
    internal static extern double get_version();

Here we tried to install vs_redist.x64.exe

What should we do to be able to load this DLL ?

RezaNoei
  • 1,266
  • 1
  • 8
  • 24

0 Answers0