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

Unable to load DLL 'libSkiaSharp' when referenced in class library targetting netstandard1.3 #2728

Open
1 task done
lbras opened this issue Jan 30, 2024 · 8 comments
Open
1 task done
Labels

Comments

@lbras
Copy link

lbras commented Jan 30, 2024

Description

SkiaSharp beginner here, using VS2019. I created an ASP.NET WebForms application, targetting .NET Framework 4.6 (=.NETStandard 1.3), and installed SkiaSharp v2.88.7 NuGet package in a class library referenced by the WebForms application, compiling as AnyCPU. On build the LibSkiaSharp.dll is not deployed to any bin folder and on runtime I get the infamous error:

Unable to load DLL 'libSkiaSharp': The specified module could not be found.

I added

<ShouldIncludeNativeSkiaSharp>True</ShouldIncludeNativeSkiaSharp>
<PreferredNativeSkiaSharp>x86</PreferredNativeSkiaSharp>

to all PropertyGroups of both the class library and Webforms application *.csproj files, but it makes no difference. I'm out of ideas... From what I could research:

I confirmed the same issue happens on version 2.80.0.
SkiaSharp v1.68.3 works fine and I do get libSkiaSharp.dll deployed in the bin folder, so for now I will continue using that version.

Code

I created a sample project to reproduce the issue and uploaded it to the following GitHub repository:

https://github.com/lbras/SkiaSharpTestWebFormsNETFramework46

Expected Behavior

LibSkiaSharp.dll should be copied to the application bin folder

Actual Behavior

LibSkiaSharp.dll is not deployed with the application, resulting in runtime errors

Version of SkiaSharp

2.88.3 (Current)

Last Known Good Version of SkiaSharp

1.x (Obsolete)

IDE / Editor

Visual Studio (Windows)

Platform / Operating System

Windows

Platform / Operating System Version

Windows 10

Devices

No response

Relevant Screenshots

No response

Relevant Log Output

[DllNotFoundException: Unable to load DLL 'libSkiaSharp': The specified module could not be found. (Exception from HRESULT: 0x8007007E)]
   SkiaSharp.SkiaApi.sk_data_new_empty() +0
   SkiaSharp.SKData..cctor() +28

[TypeInitializationException: The type initializer for 'SkiaSharp.SKData' threw an exception.]
   SkiaSharp.SKData.Create(Stream stream) +0
   SkiaSharp.SKImage.FromEncodedData(Stream data) +33
   Imaging.ImageFile.IsValid() in D:\Repos\SkiaSharpTestWebFormsNETFramework46\Imaging\ImageFile.cs:30
   SkiaSharpTestWebFormsNETFramework46._Default.Page_Load(Object sender, EventArgs e) in D:\Repos\SkiaSharpTestWebFormsNETFramework46\Web\Default.aspx.cs:21
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +85
   System.Web.UI.Control.OnLoad(EventArgs e) +79
   System.Web.UI.Control.LoadRecursive() +130
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2852

Code of Conduct

  • I agree to follow this project's Code of Conduct
@lbras lbras added the type/bug label Jan 30, 2024
@charlesroddie
Copy link

Try updating netframework to latest netframework or dotnet8 so you can use netstandard2.0 at least.

@lbras
Copy link
Author

lbras commented Feb 7, 2024

Try updating netframework to latest netframework or dotnet8 so you can use netstandard2.0 at least.

I tried updating my sample project to .NET Framework 4.8 and had no issues, SkiaSharp worked out of the box without having to add <ShouldIncludeNativeSkiaSharp> or <PreferredNativeSkiaSharp> using platform Any CPU. I confirmed the same is true for .NET Framework 4.6.2.

So it is an issue specific for .NET Framework 4.6 / .NETStandard 1.3.

@charlesroddie
Copy link

.NET Framework 4.6 is out of support so there is no expectation that this should work or not work. A search for netstandard in the repo indicates that netstandard1.3 has been removed with netstandard2.0 and netstandard2.1 and net462 as current targets, which makes sense.

@lbras
Copy link
Author

lbras commented Feb 12, 2024

I do expect it to work because SkiaSharp claims it provides bindings for .NET Standard 1.3:

image

image

If this is no longer true, then the above statements should be corrected. I specifically picked SkiaSharp because of .NET Standard 1.3 support.

@charlesroddie
Copy link

I expect those references would be removed when the current prerelease gets released. Why would this matter to you? You said you updated your project to netframework 4.8 and there was no problem.

@mattleibow
Copy link
Contributor

mattleibow commented Feb 12, 2024

Hi folks, looking at this issue I think the nuget UI and readme may not be the greatest source of how this all works.

The meaning of support for .NET Standard 1.3 really just refers to the API level. There is no real ".NET Standard" app. So you can't "run" it. This just means that if you want to build a .NET Standard dll with SkiaSharp, you can do so.

The other part is the .NET Framework, and that is just supported from 4.6.2 since that is the earliest version that supports .NET Standard 2.0.

I agree this is a bit confusing as you have to know that .NET Standard is not really meant to be used in the way you would expect.

I need to see why I do not copy the native dlls for plain .NET Standard. I am sure there was a reason. If you were to build a net8.0 class library I think it gets copied. So, it may have been that everyone using .NET Standard just used it as a library and had some form of app.

@corianderhater
Copy link

corianderhater commented Jun 6, 2024

I can relate.

The problem occurs on the line:

var canvas = SKSvgCanvas.Create(SKRect.Create(squareSvgSize, squareSvgSize), stream);

Message:
System.TypeInitializationException: 'The type initializer for 'SkiaSharp.SKAbstractManagedWStream' threw an exception.'
DllNotFoundException: Unable to load DLL 'libSkiaSharp' or one of its dependencies: The specified module could not be found. (0x8007007E)

Installed libs via nuget:
SkiaSharp 2.88.8
SkiaSkarp.Svg 1.60.0

I use .NET 7, Class Library project, AnyCPU (i tried x64 too)

The libSkiaSharp.dll exisits in all subfolders of
...\bin\Debug\net7.0\runtimes\PLATFORMNAME\native
but not in:
...\bin\Debug\net7.0\runtimes\win\lib\net7.0

Weird behavior:
I have another .NET8 project that is a WebAPI Console Application and it works just fine with Microcharts library that uses SkiaSharp 2.80.2.

Any ideas?

@david3951445
Copy link

I encountered a similiar issue in a WinForm (.NET Framework 4.8) project that use ScottPlot: (5.0.44). My situation is:

  1. git clone this project from remote
  2. Open and debug (F5) on VS2022
  3. The exception "Unable to load library 'libSkiaSharp.dll' "throw
    As lbras said, the expected behavior "LibSkiaSharp.dll should be copied to the application bin folder" not implemented.
    Even if the coping logic is already written in .csproj file of th project:

I just save .csproj outside VS2022 without changing anything and force VS2022 reload project and the files are copy to as it excepted.
Another solution is to not git ignore the packages folder. This allows the first debug (F5) to be successful. Although the packages folder will be automatically generated If packages folder ignored during the first debug (F5), the second debug (F5) will not "interpret". csproj file again (vs2022 seems to remember some past states). This lead the coping logic will not be run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Ready For Work
Development

No branches or pull requests

5 participants