VahidN / EPPlus.Core

EPPlus.Core is an unofficial port of the EPPlus library to .NET Core
GNU Lesser General Public License v3.0
370 stars 93 forks source link

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

Open BharatRajMeriyala opened 6 years ago

BharatRajMeriyala commented 6 years ago

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"]

VahidN commented 6 years ago

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

BharatRajMeriyala commented 6 years ago

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"]

dustdragonpzc commented 6 years ago

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

VahidN commented 6 years ago

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
dustdragonpzc commented 6 years ago

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

VahidN commented 6 years ago

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
dustdragonpzc commented 6 years ago

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

dustdragonpzc commented 6 years ago

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 commented 6 years ago

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

fjunqueira commented 6 years ago

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

VahidN commented 6 years ago

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 commented 6 years ago

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

taobaohi commented 6 years ago

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

justmine66 commented 6 years ago

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

xing-zheng commented 6 years ago

@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" ]