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

Graphics format PNG not available (are you missing the NuGet package Codecrete.SwissQRBill.Generator?) #68

Open
j-2-3 opened this issue Dec 30, 2024 · 5 comments

Comments

@j-2-3
Copy link

j-2-3 commented Dec 30, 2024

Having upgraded from Codecrete.SwissQRBill.Generator 2.5.3 to version 3.3.0 I receive the above mentioned error when attempting to generate a .png type of image (GraphicsFormat = GraphicsFormat.PNG)

What am I missing?

@manuelbl
Copy link
Owner

The error message sounds as if you are using the Codecrete.SwissQRBill.Core instead of Codecrete.SwissQRBill.Generator. The former one does not include PNG generation.

If this is not the case, then please describe the technical aspects of the application you are building:

  • Is it a standalone .exe, an ASP.NET application, a library etc.?
  • What platform (Windows, Linux, macOS) does it run on?
  • What version of .NET are you using?
  • Are you using trimming or a similar technique to optimize the executable?

Codecrete.SwissQRBill.Generator determines at run-time if the PNG generation capability is available. If it can't find a class providing it, it will generate the mentioned error message.

@j-2-3
Copy link
Author

j-2-3 commented Dec 30, 2024

I've tried both Codecrete.SwissQRBill.Generator as well as Codecrete.SwissQRBill.Windows
I am targeting WPF app for Windows 10 (SwissQRBill is referenced in the companion class library project).
As far as I have now discovered the error occurs when I build for .Net Framework 4.8
When compiled for .NET 8 the PNG format is handled correctly.
SVG format is handled ok in both cases.

PS Exception HResult=0x80131500
Exception stack trace:
(last line - or actually the first 🙂 - is my code)

at Codecrete.SwissQRBill.Generator.QRBill.CreateCanvas(BillFormat format)
at Codecrete.SwissQRBill.Generator.QRBill.Generate(Bill bill)
at RdExtensions.QRBillService.GetQRFileName(Invoice invoice)

@manuelbl
Copy link
Owner

manuelbl commented Dec 30, 2024

Your case sound familiar. We've seen it before. If Codecrete.SwissQRBill.Windows is indirectly referenced (e.g. Application -> Class Library Project -> SwissQRBill package), then Visual Studio seems to optimize Codecrete.SwissQRBill.Generator or Codecrete.SwissQRBill.Windows away and only reference Codecrete.SwissQRBill.Core.

To prevent it, add the following code to the class generating the QR bill:

    new PNGCanvasFactory().Register();

@manuelbl
Copy link
Owner

I've taken the case to extend the README. See https://github.com/manuelbl/SwissQRBill.NET?tab=readme-ov-file#png-generation.

The better code to include might be CanvasCreator.Register(new PNGCanvasFactory());. It works with both Codecrete.SwissQRBill.Generator or Codecrete.SwissQRBill.Windows.

@j-2-3
Copy link
Author

j-2-3 commented Dec 31, 2024

Thanks a lot!
This workaround does it! 👍

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

No branches or pull requests

2 participants