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

Open
Akash26Arul opened this issue Feb 7, 2024 · 5 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.

Copy link
Contributor

Hi @Akash26Arul. We have added the status/needs-info label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@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.

Copy link
Contributor

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate.

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

3 participants