manuelbl / SwissQRBill.NET

.NET library for Swiss QR bill payment slips (aka QR-Rechnung)
MIT License
88 stars 33 forks source link

Codecrete.SwissQRBill.Generator.QRBillGenerationException: Graphics format PNG not available #54

Closed HerreraG closed 1 year ago

HerreraG commented 2 years ago

Hello everyone!

I am upgrading from version 2.4.3 to version 3.0.5 and I get this exception when I want to generate the QR Bill in .PNG format.

Codecrete.SwissQRBill.Generator.QRBillGenerationException: 'Graphics format PNG not available (are you missing the NuGet package Codecrete.SwissQRBill.Generator?)'

Works well in SVG and PDF formats.

The framework of my project is .NET 4.6.1.

Supposedly this issue was fixed with version 3.0.1, in my case it is not. Graphics format PNG not available

Thank you in advance.

manuelbl commented 2 years ago

What NuGet packages (related to Swiss QR bill) does your project refer to? Do you have a .NET project for a Windows application, or another project type? Do you have a complex project with multiple subprojects? Is so, what does the project structure look like?

HerreraG commented 2 years ago

Hi @manuelbl, thank you for your help!

What NuGet packages (related to Swiss QR bill) does your project refer to?

Codecrete.SwissQRBill.Core 3.0.5 Codecrete.SwissQRBill.Generator 3.0.5 Net.Codecrete.QrCodeGenerator 2.0.0 QRCoder 1.2.9

Do you have a .NET project for a Windows application, or another project type?

ASP.NET Web API

Do you have a complex project with multiple subprojects?

No, I have a library class project where I have installed the Codecrete.SwissQRBill.Generator package and that is where I generate the QR bill. Then from the ASP.NET Web API project I add the library class project as a reference to generate the QR bill.

manuelbl commented 2 years ago

I can reproduce the problem in this specific configuration:

The problem is related to limitations of how NuGet packages are handled in old .NET projects using packages.config. The assembly Codecrete.SwissQRBill.Generator is not identified as a required dependency.

I've also found that Codecrete.SwissQRBill.Generator, which is based on SkiaSharp graphics library, doesn't nicely work with ASP.NET projects (or more likely the web server used).

Two changes are needed:

Change 1: Use the package Codecrete.SwissQRBill.Windows instead of Codecrete.SwissQRBill.Generator. That's the preferred choice for Windows only projects and for .NET Framework projects anyway.

Change 2: Create a direct reference to Codecrete.SwissQRBill.Windows, so it doesn't get left behind.

        static BillGeneratorClass()
        {
            new PNGCanvasFactory().Register();
        }