.Net Core web API Docker (Linux) - unable to load libMyCpp.so file


I have a .NetCore web API and and need to connect with a C++ shared library (libCppAppOutput.so). For this I am using DllImport inside the controller of the Web API as in the below code:

[DllImport("libCppAppOutput.so", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, EntryPoint = "methodNameinCppProject")] 
public static extern int MethodNameInWebAPI(string param1, string param2);

When I am debugging it in Visual studio with Windows environment, I am getting an exception like

An attempt was made to load a program with an incorrect format. (0x8007000B).

This may be because of trying to access a Linux file in Windows environment, if I am using a CppAppOutput.dll in place of libCppAppOutput.so I can successfully call the methods inside the dll. But my actual requirement is to run the entire application in Linux environment and to be proceed with .so file only, so I have created a docker image with target OS as Linux and tried to call the methods inside it from running docker with the below command :

docker run -p 8081:80 name_of_docker_image:tagname

Then I am getting an exception like:

Unable to load shared library 'libCppAppOutput.so' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: libCppAppOutput.so: cannot open shared object file: No such file or directory.

But I can see the file, libCppAppOutput.so is present inside the docker image by using the following commands,

docker create --name name_of_container name_of_docker_image:tagname
docker start name_of_container 
docker exec -ti name_of_container /bin/bash
root@xyzabc:/app# ls

I am using below URL to test the application


Please help me in this regard like how can I call a .so file from the Linux docker. if this issue to be elaborated more, kindly comment and I will do. Thanks in advance.

asked on Stack Overflow Nov 21, 2020 by Colbay • edited Nov 22, 2020 by Colbay

1 Answer


I could able to solve this issue with help from my colleagues and friends. There was a dependency with libCppAppOutput.so (an XML parser). Even though that dependency package is installed in the container, it was missed to configure while creating the libCppAppOutput.so. This was identified by executing ldl libCppAppOutput.so command in bash.

Thank you all for spend time on reading and analyzing the question ! Have more N more great coding days!

answered on Stack Overflow Nov 28, 2020 by Colbay

User contributions licensed under CC BY-SA 3.0