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

System.DllNotFoundException: libSkiaSharp exception is thrown in Blazor WASM .NET 8.0 #2745

Closed
Akash26Arul opened this issue Feb 7, 2024 · 4 comments

Comments

@Akash26Arul
Copy link

Akash26Arul commented Feb 7, 2024

Description

System.DllNotFoundException: libSkiaSharp exception is thrown while using SkiaSharp library in Blazor WASM .NET 8.0 and this issue doesn't occur in Blazor WASM .NET 6.0.

Stack trace:

System.TypeInitializationException: The type initializer for 'SkiaSharp.SKImageInfo' threw an exception.
---> System.DllNotFoundException: libSkiaSharp
at SkiaSharp.SKImageInfo..cctor()

Note:
When trying the same approach in Blazor WASM .NET 6.0, there is no issues.

Code

try 
{ 
    using (SKBitmap bitmap = new SKBitmap(500, 500, SKImageInfo.PlatformColorType, SKAlphaType.Premul)) 
    { 
        using (SKSurface sKSurface = SKSurface.Create(bitmap.Info)) 
        { 
            SKCanvas sKCanvas = sKSurface.Canvas; 
            SKPaint sKPaint = new SKPaint(); 
            sKPaint.Color = new SKColor(255, 0, 0); 
            sKCanvas.DrawText("Blazor", new SKPoint(250, 250), sKPaint); 
            MemoryStream stream = new MemoryStream(); 
            sKSurface.Snapshot().Encode(SKEncodedImageFormat.Png, 100).SaveTo(stream); 
        } 
    } 
} 
catch (Exception ex) 
{ 
    ex.ToString(); 
} 

Expected Behavior

Should draw the text and save as png.

Actual Behavior

Throws the above mentioned exception (System.DllNotFoundException: libSkiaSharp)

Version of SkiaSharp

2.88.6

Last Known Good Version of SkiaSharp

None

IDE / Editor

Visual Studio (Windows)

Platform / Operating System

Windows

Platform / Operating System Version

.NET 8.0

ASP.NET Core .NET 8.0 : Working fine

Blazor server side .NET 8.0 : Working fine

Blazor client side (WASM) .NET 8.0 : Facing Lib SkiaSharp issue

@Akash26Arul Akash26Arul changed the title [BUG] <title>System.DllNotFoundException: libSkiaSharp exception is thrown in Blazor WASM .NET 8.0 System.DllNotFoundException: libSkiaSharp exception is thrown in Blazor WASM .NET 8.0 Feb 7, 2024
@Akash26Arul
Copy link
Author

Hi team,

Any update on this?

Regards,
Akash.

@torourke55
Copy link

I was able to run your code after adding SkiaSharp.Views.Blazor package. https://www.nuget.org/packages/SkiaSharp.Views.Blazor/2.88.7. I'm using WASM .NET 8.0 Visual Studio 2022 version 17.9.1.

@mattleibow
Copy link
Contributor

You need to either install SkiaSharp.Views.Blazor or SkiaSharp.NativeAssets.WebAssembly in order to get the binaries for WASM.

Try the latest versions as we have also fixed several packaging issues.

@gismofx
Copy link

gismofx commented Nov 24, 2024

SkiaSharp.Views.Blazor

I'm getting the same issue. I tried the latest release and the latest preview release.

I found a thread from a few years ago #1725

Doing this is a work-around:

	<ItemGroup>
		<NativeFileReference Include="$(HarfBuzzSharpStaticLibraryPath)\8.3.1-preview.1.2\*.a" />
	</ItemGroup>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants