Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve GDIP exception when failing to load libgdiplus or GDI+ #29404

Closed
jlestercastro opened this issue Apr 29, 2019 · 18 comments
Closed

Improve GDIP exception when failing to load libgdiplus or GDI+ #29404

jlestercastro opened this issue Apr 29, 2019 · 18 comments
Labels
area-System.Drawing help wanted [up-for-grabs] Good issue for external contributors
Milestone

Comments

@jlestercastro
Copy link

Hi ,
Someone please help to fix this error

I've always got "The type initializer for 'Gdip' threw an exception." when i deploy my .NetCore API in ubuntu server. But the codes is working in my local machine (Windows).

I'm trying to get a image icon in my server folder named pictures/3FALogo.ico
12

C# code getting the icon.
23

I' ve always got this error message response. when accessing the API endpoint in Ubuntu Server.
54

Someone can help to fix this error.
Thank you.

@omariom
Copy link
Contributor

omariom commented Apr 29, 2019

GDI+ is Windows only tech.
ImageSharp is cross-platform.

@danmoseley
Copy link
Member

On Unix, we use libgdi+ for GDI+ so I would think this should work. I would start by investigating this as a possible failure to load the shared library. Set LD_DEBUG and go from there.

Longer term you might consider other libraries, since System.Drawing is not expected to get much investment - it is very old.

@jlestercastro
Copy link
Author

GDI+ is Windows only tech.
ImageSharp is cross-platform.

Thank you.
I've installed "libc6-dev" in my linux server and it works.

@danmoseley
Copy link
Member

@jlestercastro ideally that message would be more helpful. @safern would it make sense to wrap the Gdip() static constructor in a try/catch to add some more useful information, such as to make sure libgdiplus version XYZ or later is available, and possibly to try LD_DEBUG?

If we load by the runtime API, it will show this message today, and I know it has helped some people:

  507:     IDS_EE_NDIRECT_LOADLIB_LINUX            "Unable to load shared library '%1' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: %2"

@safern
Copy link
Member

safern commented May 1, 2019

Yes it would make sense. We could potentially just wrap this call: https://github.com/dotnet/corefx/blob/dee434428ee392302ff2050bbee304c9fce68b2f/src/System.Drawing.Common/src/System/Drawing/Gdiplus.cs#L77

I will rename the title and mark as up for grabs and 3.0.

@safern safern changed the title GDIP Threw an exception on Ubunto server Improve GDIP exception when failing to load libgdiplus or GDI+ May 1, 2019
@eanova
Copy link
Contributor

eanova commented May 10, 2019

I'd like to tackle this one.

@danmoseley
Copy link
Member

@eanova sure - it's yours. Thanks

@safern
Copy link
Member

safern commented May 14, 2019

@eanova let me know if you need any help on this workitem.

@safern
Copy link
Member

safern commented May 14, 2019

@karelz I can't assign the issue to @eanova eventhough is a Contributor. Could you help assigning?

@karelz
Copy link
Member

karelz commented May 15, 2019

I sent @eanova collaborator invite - that will make it work. Please ping us here once you accept.
Also, it will auto-subscribe you to all notifications from the repo (500+ per day). We recommend to switch the repo to Not Watching -- which will give you notifications for all your mentions, assignments and explicit subscriptions to issues.

@eanova
Copy link
Contributor

eanova commented May 15, 2019

Accepted!

@safern
Copy link
Member

safern commented May 29, 2019

@jlestercastro I re-named the issue to improve the exception message and I believe @eanova is working on it, so I will re-open the issue to track that work.

@safern safern reopened this May 29, 2019
@eanova
Copy link
Contributor

eanova commented May 29, 2019

Hi everyone! I've been chipping away at this and trying to get comfortable tooling at the same time. I found this article that discusses Mono debugging of libgdiplus using LD_DEBUG helpful.
https://www.mono-project.com/docs/gui/problemgdiplusinit/

I guess there really isn't more information we can capture such as individual dependencies that are missing. So I'll pretty much stick to what @danmosemsft has already suggested

I'll test the situation on the Mac, and then send a PR.

@danmoseley
Copy link
Member

Moving to Future. Work can still happen, but it's not essential that we fix this before ship 3.0.

@eanova
Copy link
Contributor

eanova commented Jun 7, 2019

Is there an effective way to debug a local build of System.Drawing.Common. I've tried the method described in the dogfooding article but Nuget can't seem to find the nupkg. Or is there away to see the debug output within the xUnit console?

@safern
Copy link
Member

safern commented Jun 11, 2019

Is there an effective way to debug a local build of System.Drawing.Common

Does running the CoreFX test's doesn't help?

If you want to use a local build of corefx rather than running the tests you can do the following:
run build -allConfigurations in your corefx repo. That will produce some packages in your local repository under artifacts\packages\<BuildConfiguration> which in this case <BuildConfiguration> will be Debug. You will find a System.Drawing.Common package with a 4.6.0-dev version.

Once you have that, you can add a NuGet.config with nuget.org and your local folder as restore sources. Also, you can directly add the restore sources on your csproj like this:

<PropertyGroup>
    <RestoreSources>
         https://api.nuget.org/v3/index.json;
         <PathToCorefx>\artifacts\packages\Debug\;
         $(RestoreSources) 
   </RestoreSources>
</PropertyGroup>

@eanova
Copy link
Contributor

eanova commented Jun 13, 2019

@safern Thanks, I was finally able to get the -allconfigurations flag to work. I'll be pushing some simple fixes that I needed to get it to work. Adding the restore to the project file is working as well.

@eanova eanova removed their assignment Aug 21, 2019
@msftgits msftgits transferred this issue from dotnet/corefx Feb 1, 2020
@msftgits msftgits added this to the Future milestone Feb 1, 2020
@jlestercastro
Copy link
Author

Thank you everyone

@ghost ghost locked as resolved and limited conversation to collaborators Dec 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Drawing help wanted [up-for-grabs] Good issue for external contributors
Projects
None yet
Development

No branches or pull requests

7 participants