mono / SkiaSharp

SkiaSharp is a cross-platform 2D graphics API for .NET platforms based on Google's Skia Graphics Library. It provides a comprehensive 2D API that can be used across mobile, server and desktop models to render images.
MIT License
4.45k stars 540 forks source link

[BUG] SkiaSharp not working when deploy Blazor client side application (.NET 7.0) to Azure App Service (Windows) using GitHub Actions (CI/CD Pipeline) #2411

Open SuriyaBalamurugan opened 1 year ago

SuriyaBalamurugan commented 1 year ago

Description

We are using SkiaSharp in Blazor WebAssembly (client side) application. When deploy Blazor client side application (.NET 6.0) to Azure App Service (Windows) using GitHub Actions (CI/CD Pipeline), SkiaSharp works fine without any issue. But when we deploy Blazor client side application (.NET 7.0) to Azure App Service (Windows) using GitHub Actions (CI/CD Pipeline) we are facing libSkiaSharp assembly not found issue.

Code

@page "/skiasharptest"
@inject Microsoft.JSInterop.IJSRuntime JS
@inject HttpClient client
@using SkiaSharp;
@using System.IO

<h2>Hello, world!</h2>
<p>Click the button to draw the text using SkiaSharp.</p>
<button class="btn btn-primary" @onclick="@Create">Create</button>

<p role="status">Status: @msg</p>

@functions {
    public string msg = string.Empty;
    async void Create()
    {
        try
        {
            //Get the text to draw.
            String drawText = "Hello";
            //Create sKImageInfo object
            SKImageInfo sKImageInfo = new SKImageInfo(612, 792);
            SKSurface sKSurface = SKSurface.Create(sKImageInfo);
            SKCanvas canvas = sKSurface.Canvas;
            //Create font. 
            SKTypeface sKTypeface = SKTypeface.FromFamilyName("Calibri Light", SKFontStyle.Bold);
            SKPaint paint = new SKPaint();
            paint.TextSize = 11f;
            paint.Typeface = sKTypeface;
            canvas.DrawText(drawText, 0, 0, paint);
            msg = "End";
        }
        catch (Exception ex)
        {
            msg = ex.ToString();
            msg += ex.Message;
            msg += ex.StackTrace.ToString();
        }
    }
}

Expected Behavior

SkiaSharp should work properly when deploy Blazor client side application (.NET 7.0) to Azure App Service (Windows) using GitHub Actions (CI/CD Pipeline).

Actual Behavior

The following exception is thrown.

System.TypeInitializationException: TypeInitialization_Type, SkiaSharp.SKImageInfo ---> System.DllNotFoundException: libSkiaSharp at SkiaSharp.SKImageInfo..cctor() Exception_EndOfInnerExceptionStack at Blazor_SkiaSharp.Pages.SkiaSharpTest.Create()TypeInitialization_Type, SkiaSharp.SKImageInfo at Blazor_SkiaSharp.Pages.SkiaSharpTest.Create()

Basic Information

Reproduction Link

Attached both .NET 7.0 and .NET 6.0 samples along with workflow file, Blazor-GitHub-Actions.zip

Reference videos for how to deploy app to Azure using GitHub Actions (CI/CD Pipeline)

https://www.youtube.com/watch?v=UpWeffxf790 https://www.youtube.com/watch?v=QP0pi7xe24s https://learn.microsoft.com/en-us/azure/app-service/deploy-github-actions?tabs=applevel

Saibamen commented 1 year ago

Are you using Docker to build image?

SuriyaBalamurugan commented 1 year ago

Hi Saibamen,

I’m not using Docker to build an image. I deployed to App Service using GitHub Actions. The GitHub Actions workflow directly builds and deploy the application without containerization.

Regards, Suriya Balamurugan.