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

[BUG] SkiaSharp v3.116.0 System.TypeInitializationException when executing as Azure Linux Function (.NET 9.0 - isolated) #3103

Open
1 task done
HmichaelG opened this issue Dec 5, 2024 · 0 comments
Labels

Comments

@HmichaelG
Copy link

HmichaelG commented Dec 5, 2024

Description

The following code executes successfully...

  1. when executed locally within VS2022.
  2. when executed within Docker desktop

but fails when executed as an Azure Linux Function app (.NET 9.0 - isolated).

Code

The test project: https://github.com/HmichaelG/SkiaTest

program.cs

using Microsoft.Azure.Functions.Worker.Builder;
using Microsoft.Extensions.Hosting;

var builder = FunctionsApplication.CreateBuilder(args);

builder.ConfigureFunctionsWebApplication();

// Application Insights isn't enabled by default. See https://aka.ms/AAt8mw4.
// builder.Services
//     .AddApplicationInsightsTelemetryWorkerService()
//     .ConfigureFunctionsApplicationInsights();

builder.Build().Run();

function

using System;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Extensions.Logging;
using SkiaSharp;
using System.IO;

namespace SkiaTest
{
    public class SkiaTest
    {
        private readonly ILogger _logger;

        public SkiaTest(ILoggerFactory loggerFactory)
        {
            _logger = loggerFactory.CreateLogger<SkiaTest>();
        }

        [Function("SkiaTest")]
        public void Run([TimerTrigger("0 */5 * * * *", RunOnStartup = true)] TimerInfo myTimer)
        {
            var path = Path.GetTempPath();
            var outputFile = Path.Combine(path, "report.pdf");

            _logger.LogInformation("Writing to file...");
            // Create a PDF document
            var metadata = new SKDocumentPdfMetadata
            {
                Author = "Your Name",
                Title = "Sample PDF Report",
                Creation = DateTime.Now,
                Modified = DateTime.Now
            };

            using (var stream = File.Create(outputFile))
            {
                var document = SKDocument.CreatePdf(stream, metadata);
                using (var canvas = document.BeginPage(612, 792)) // A4 size in points
                {
                    canvas.Clear(SKColors.White);
                    using (var paint = new SKPaint
                    {
                        Color = SKColors.Black,
                        TextSize = 24
                    })
                    {
                        canvas.DrawText("Hello, World!", 100, 100, paint);
                    }
                }
                document.EndPage();
                document.Close();
            }
            _logger.LogInformation($"File written to: {outputFile}");

            if (myTimer.ScheduleStatus is not null)
            {
                _logger.LogInformation($"Next timer schedule at: {myTimer.ScheduleStatus.Next}");
            }
        }

    }
}

Expected Behavior

a report named "report.pdf" be created in the temp directory.

Actual Behavior

Result: Function 'SkiaTest', Invocation id '0245d8d8-2e4c-4d91-8363-5828a29c182a': An exception was thrown by the invocation.
Exception: System.TypeInitializationException: The type initializer for 'SkiaSharp.SKAbstractManagedWStream' threw an exception.
 ---> System.DllNotFoundException: Unable to load shared library 'libSkiaSharp' or one of its dependencies. In order to help diagnose loading problems, consider using a tool like strace. If you're using glibc, consider setting the LD_DEBUG environment variable: 
/usr/share/dotnet/shared/Microsoft.NETCore.App/9.0.0/libSkiaSharp.so: cannot open shared object file: No such file or directory
/home/site/wwwroot/libSkiaSharp.so: cannot open shared object file: No such file or directory
/usr/share/dotnet/shared/Microsoft.NETCore.App/9.0.0/liblibSkiaSharp.so: cannot open shared object file: No such file or directory
/home/site/wwwroot/liblibSkiaSharp.so: cannot open shared object file: No such file or directory
/usr/share/dotnet/shared/Microsoft.NETCore.App/9.0.0/libSkiaSharp: cannot open shared object file: No such file or directory
/home/site/wwwroot/libSkiaSharp: cannot open shared object file: No such file or directory
/usr/share/dotnet/shared/Microsoft.NETCore.App/9.0.0/liblibSkiaSharp: cannot open shared object file: No such file or directory
/home/site/wwwroot/liblibSkiaSharp: cannot open shared object file: No such file or directory

   at SkiaSharp.SkiaApi.sk_managedwstream_set_procs(SKManagedWStreamDelegates procs)
   at SkiaSharp.SkiaApi.sk_managedwstream_set_procs(SKManagedWStreamDelegates procs)
   at SkiaSharp.SKAbstractManagedWStream..cctor()
   --- End of inner exception stack trace ---
   at SkiaSharp.SKAbstractManagedWStream..ctor(Boolean owns)
   at SkiaSharp.SKManagedWStream..ctor(Stream managedStream, Boolean disposeManagedStream, Boolean owns)
   at SkiaSharp.SKManagedWStream..ctor(Stream managedStream, Boolean disposeManagedStream)
   at SkiaSharp.SKManagedWStream..ctor(Stream managedStream)
   at SkiaSharp.SKDocument.CreatePdf(Stream stream, SKDocumentPdfMetadata metadata)
   at SkiaTest.SkiaTest.Run(TimerInfo myTimer) in D:\source\FunctionAppLatest\FunctionApp1\SkiaTest.cs:line 36
   at SkiaTest.DirectFunctionExecutor.ExecuteAsync(FunctionContext context) in D:\source\FunctionAppLatest\FunctionApp1\obj\Release\net9.0\linux-x64\Microsoft.Azure.Functions.Worker.Sdk.Generators\Microsoft.Azure.Functions.Worker.Sdk.Generators.FunctionExecutorGenerator\GeneratedFunctionExecutor.g.cs:line 37
   at Microsoft.Azure.Functions.Worker.OutputBindings.OutputBindingsMiddleware.Invoke(FunctionContext context, FunctionExecutionDelegate next) in D:\a\_work\1\s\src\DotNetWorker.Core\OutputBindings\OutputBindingsMiddleware.cs:line 13
   at Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore.FunctionsHttpProxyingMiddleware.Invoke(FunctionContext context, FunctionExecutionDelegate next) in D:\a\_work\1\s\extensions\Worker.Extensions.Http.AspNetCore\src\FunctionsMiddleware\FunctionsHttpProxyingMiddleware.cs:line 38
   at Microsoft.Azure.Functions.Worker.FunctionsApplication.InvokeFunctionAsync(FunctionContext context) in D:\a\_work\1\s\src\DotNetWorker.Core\FunctionsApplication.cs:line 96
Stack:    at SkiaSharp.SKAbstractManagedWStream..ctor(Boolean owns)
   at SkiaSharp.SKManagedWStream..ctor(Stream managedStream, Boolean disposeManagedStream, Boolean owns)
   at SkiaSharp.SKManagedWStream..ctor(Stream managedStream, Boolean disposeManagedStream)
   at SkiaSharp.SKManagedWStream..ctor(Stream managedStream)
   at SkiaSharp.SKDocument.CreatePdf(Stream stream, SKDocumentPdfMetadata metadata)
   at SkiaTest.SkiaTest.Run(TimerInfo myTimer) in D:\source\FunctionAppLatest\FunctionApp1\SkiaTest.cs:line 36
   at SkiaTest.DirectFunctionExecutor.ExecuteAsync(FunctionContext context) in D:\source\FunctionAppLatest\FunctionApp1\obj\Release\net9.0\linux-x64\Microsoft.Azure.Functions.Worker.Sdk.Generators\Microsoft.Azure.Functions.Worker.Sdk.Generators.FunctionExecutorGenerator\GeneratedFunctionExecutor.g.cs:line 37
   at Microsoft.Azure.Functions.Worker.OutputBindings.OutputBindingsMiddleware.Invoke(FunctionContext context, FunctionExecutionDelegate next) in D:\a\_work\1\s\src\DotNetWorker.Core\OutputBindings\OutputBindingsMiddleware.cs:line 13
   at Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore.FunctionsHttpProxyingMiddleware.Invoke(FunctionContext context, FunctionExecutionDelegate next) in D:\a\_work\1\s\extensions\Worker.Extensions.Http.AspNetCore\src\FunctionsMiddleware\FunctionsHttpProxyingMiddleware.cs:line 38
   at Microsoft.Azure.Functions.Worker.FunctionsApplication.InvokeFunctionAsync(FunctionContext context) in D:\a\_work\1\s\src\DotNetWorker.Core\FunctionsApplication.cs:line 96 

Version of SkiaSharp

3.116.0 (Current)

Last Known Good Version of SkiaSharp

2.88.7 (Deprecated)

IDE / Editor

Visual Studio (Windows)

Platform / Operating System

Linux

Platform / Operating System Version

Azure Linux Function app - .NET 9.0

Please note this appears to be a .NET 9.0 issue.
SkiaSharp 2.88.7 works fine on .NET 8.0
SkiaSharp 2.887 + fails on .NET 9.0

Devices

Not applicable

Relevant Screenshots

No response

Relevant Log Output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@HmichaelG HmichaelG changed the title [BUG] SkiaSharp v3.116.0 System.TypeInitializationException when executing as Azure Linux Function [BUG] SkiaSharp v3.116.0 System.TypeInitializationException when executing as Azure Linux Function (.NET 9.0 - isolated) Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: New
Development

No branches or pull requests

1 participant