EPPlus.Core icon indicating copy to clipboard operation
EPPlus.Core copied to clipboard

Getting the error "Unable to load DLL 'libdl'" on Ubuntu docker container with container image, microsoft/aspnetcore-build:2.0

Open BharatRajMeriyala opened this issue 7 years ago • 15 comments
trafficstars

I am trying to generate the excel sheet, using EPPlus.Core in dotnet core 2.0 framework. The generation works fine on local machine running windows. When I test the same on Ubuntu docker images, it fails with the below exception:

Unable to load DLL 'libdl': The specified module or one of its dependencies could not be found. (Exception from HRESULT: 0x8007007E) at Interop.Libdl.dlopen(String fileName, Int32 flag) at System.Drawing.SafeNativeMethods.Gdip.LoadNativeLibrary() at System.Drawing.SafeNativeMethods.Gdip..cctor()

The same used to work fine when I used the dotnet core 1.1, with libgdiplus being explicitely installed. But this setup fails with dotnet core 2.0.

The complete docker file is as below:

FROM microsoft/aspnetcore-build:2.0

RUN apt-get update RUN apt-get install -y libgdiplus

RUN npm install typings -g

COPY . /app WORKDIR /app/MyWeb

RUN ["dotnet", "--info"] RUN ["dotnet", "restore"]

EXPOSE 5000/tcp ENV ASPNETCORE_URLS http://*:5000

RUN ["dotnet", "publish"]

WORKDIR /app/MyWeb/bin/Debug/netcoreapp2.0/publish

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

BharatRajMeriyala avatar Dec 20 '17 04:12 BharatRajMeriyala

symlink /lib64/libdl.so.2 to /lib64/libdl.so More info

VahidN avatar Dec 20 '17 10:12 VahidN

I am not sure its possible to create a symlink in docker container.

https://stackoverflow.com/questions/31881904/docker-follow-symlink-outside-context

And I updated my docker file like below, I still get the same error. I am using Ubuntu 16.04 in my production environment.


FROM microsoft/aspnetcore-build:2.0

RUN apt-get update RUN apt-get install -y libgdiplus

RUN npm install typings -g

RUN ln -s /lib64/libdl.so.2 /lib64/libdl.so

COPY . /app WORKDIR /app/MyWeb

RUN ["dotnet", "--info"] RUN ["dotnet", "restore"]

EXPOSE 5000/tcp ENV ASPNETCORE_URLS http://*:5000

RUN ["dotnet", "publish"]

WORKDIR /app/MyWeb/bin/Debug/netcoreapp2.0/publish

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

BharatRajMeriyala avatar Dec 20 '17 10:12 BharatRajMeriyala

I also have some problem. use ln -s /lib64/libdl.so.2 /lib64/libdl.so , But it doesn't work in the Docker , I am using Centos 7.3 64bit

dustdragonpzc avatar Dec 28 '17 02:12 dustdragonpzc

Revert to v1.5.2 which uses CoreCompat.System.Drawing.v2 for now. v1.5.4 uses Microsoft's System.Drawing.Common library. It's in the preview phase right now.

 Install-Package EPPlus.Core -Version 1.5.2

Also you need to install libgdiplus too.

For Ubuntu 16.04 and above:
    apt-get install libgdiplus
    cd /usr/lib
    ln -s libgdiplus.so gdiplus.dll

VahidN avatar Dec 28 '17 15:12 VahidN

when I run install libgdiplus ,I only find libgdiplus.so.0 in /usr/lib64, not find libgdiplus.so ,then I run cd /usr/lib64 ln -s libgdiplus.so.0 gdiplus.dll, but it also dosen't work I am using Centos 7.3 64bit

dustdragonpzc avatar Dec 29 '17 06:12 dustdragonpzc

For CentOS 7 and above:

    yum install autoconf automake libtool
    yum install freetype-devel fontconfig libXft-devel
    yum install libjpeg-turbo-devel libpng-devel giflib-devel libtiff-devel libexif-devel
    yum install glib2-devel cairo-devel
    git clone https://github.com/mono/libgdiplus
    cd libgdiplus
    ./autogen.sh
    make
    make install
    cd /usr/lib64/
    ln -s /usr/local/lib/libgdiplus.so gdiplus.dll

VahidN avatar Dec 29 '17 06:12 VahidN

why the command yum install libgdiplus dosen't work,must execute the commands you write

dustdragonpzc avatar Dec 29 '17 06:12 dustdragonpzc

I did it according to what you said

root@izuf6fv1dbvhuu4bilrjg5z:~# find / -name libgdiplus.so
/usr/local/lib/libgdiplus.so
/root/libgdiplus/src/.libs/libgdiplus.so
root@izuf6fv1dbvhuu4bilrjg5z:~# find / -name gdiplus.dll
/usr/lib64/gdiplus.dll

but the excption is also existence The type initializer for 'System.Drawing.GDIPlus' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'gdiplus': The specified module or one of its dependencies could not be found.

dustdragonpzc avatar Dec 29 '17 07:12 dustdragonpzc

I according to http://www.mono-project.com/docs/advanced/pinvoke/dllnotfoundexception/ I slove this problem thank for VahidN

dustdragonpzc avatar Dec 29 '17 07:12 dustdragonpzc

The only way i was able to work around this issue was by reverting to v1.5.2 and adding the following symlink: ln -s libgdiplus.so gdiplus.dll to my Docker image

Thanks @VahidN

fjunqueira avatar Jan 19 '18 13:01 fjunqueira

If you are using 1.5.4, update your System.Drawing.Common dependency. This official package has 3 updates now: https://www.nuget.org/packages/System.Drawing.Common/

VahidN avatar Mar 05 '18 08:03 VahidN

About Unable to load DLL 'libdl' error in containers, they are suggesting:

  • Install libgdiplus and libc6-dev in your container (If you're on Ubuntu or Debian, you can try to install the libc6-dev package to get libdl.so).
  • Check /usr/lib/x86_64-linux-gnu/libdl.so file exists inside your container.
  • If it still fails, you can try setting LD_LIBRARY_PATH to $LD_LIBRARY_PATH:/usr/lib/x86_64-linux-gnu but that should be included already.
  • If that still fails, you can set the LD_DEBUG environment variable to libs in your Dockerfile, restart your container.

VahidN avatar Mar 05 '18 09:03 VahidN

FROM microsoft/aspnetcore RUN apt-get update RUN apt-get install -y apt-utils RUN apt-get install -y libgdiplus RUN ln -s /usr/lib/libgdiplus.so /usr/lib/gdiplus.dll WORKDIR /app COPY /app ./ EXPOSE 8082 ENTRYPOINT ["dotnet", "WebApp.dll"]

is ok

taobaohi avatar May 25 '18 03:05 taobaohi

samples: dotnet-ascpnetcore-runtime:2.1 xx.csproj file: image Dockerfile file: image or directly use the images i had buit: https://hub.docker.com/r/justmine/dotnet-aspnetcore-runtime-gdiplus it is ok !!! 亲测可用 image

justmine66 avatar Jun 14 '18 06:06 justmine66

@justmine66 It works for me, but package lsof may be unnecessary, and make symbol link for gidplus.dll is also unnecessary.

FROM microsoft/dotnet:2.1-aspnetcore-runtime
WORKDIR /app
COPY ./EPPlusOnDocker .

RUN apt-get update \
    && apt-get install -y --no-install-recommends libgdiplus libc6-dev \
    && rm -rf /var/lib/apt/lists/*
    
ENTRYPOINT [ "dotnet", "EPPlusOnDocker.dll" ]

xing-zheng avatar Jun 24 '18 14:06 xing-zheng