manuelbl / SwissQRBill.NET

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

PNGCanvas exception with 3.0.1 version #45

Closed Coradis closed 2 years ago

Coradis commented 2 years ago

Hi,

I've a working .net 4.62 project that generates QR bill with Codecrete.SwissQRBill.Generator 2.5.3 version.

I've tryed to update to 3.0.1 version and I got this exception :

Impossible de charger le fichier ou l'assembly 'SkiaSharp, Version=2.80.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756' ou une de ses dépendances. Impossible de vérifier la signature de nom fort. L'assembly a pu être falsifié ou il est à signature différée, mais pas totalement signé avec la clé privée correcte. (Exception de HRESULT : 0x80131045)

The code is ; " using (PNGCanvas canvas = new PNGCanvas(QRBill.QrBillWidth, QRBill.QrBillHeight, 300, "Helvetica, Arial, Sans")) { ..... } " I rollback to 2.5.3 and it work fine

Thank's a lot for help Best regards, Herve

manuelbl commented 2 years ago

Am I correctly assuming that you are managing dependencies with the NuGet package manager?

I'm surprised to see that SkiaSharp version 2.80.0 is used instead of the latest version 2.80.3. Are you using this library yourself, or do you have another NuGet package that depends on it?

Can you try to upgrade it to version 2.80.3?

Coradis commented 2 years ago

Hi Manuel, thx for your answer, yes I use the Nuget package manager, I just updated Codecrete.SwissQRBill.Generator 2.5.3 to 3.0.1 by the Nuget Manager and automatically SkiaSharp is added, with the correct version 2.8.3, hereafter the code in the csproj :

< Reference Include="SkiaSharp, Version=2.80.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">

..\..\packages\SkiaSharp.2.80.3\lib\net462\SkiaSharp.dll

< /Reference >

Maybe it's only related to my environment (?) I found this in my resarch :

https://github.com/mono/SkiaSharp/issues/1767

It doesn't really help me at the moment, I keep looking.

Best regards, Herve

manuelbl commented 2 years ago

The linked SkiaSharp bug could indeed be the problem. Unfortunately, it hasn't been resolved it.

It also indicates that your project relies on strong-named assemblies.

I will investigate what I can do so that the latest QR Bill library can be used with earlier SkiaSharp libraries. They should be sufficient.

manuelbl commented 2 years ago

Can you provide more information about your project as I'm still unable to reproduce it (even though the invalid strong-naming of SkiaSharp certainly is a problem).

Coradis commented 2 years ago

Hi,

  1. What kind of project settings do you have that require strong-named assemblies?

I am not familiar with the concept of strong-named assemblies, Is this related to the fact that we sign our ClickOnce manifests?

25-02-2022 16-30-18

  1. Does the error occur if the application is run from Visual Studio or just after installing it?

From VS (2017 version) in debug mode.

  1. Do you use some third-party assemblies that are installed in the GAC?

The only one that comes to mind is Telerik (UI for WPF)

Best regards Herve

manuelbl commented 2 years ago

I've already tried this setting and unfortunately it's not sufficient to reproduce the problem.

Would it be possible that you share the project file (just the .csproj, .targets, .proj or whatever you use, without the source code except for AssemblyInfo.cs and app.manifest if used)?

I think I have a solution but haven't been able to verify it.

Coradis commented 2 years ago

I will send you the source code in my next message, hereafter the steps to update to 3.0.1 :

  1. Update to 3.0.1 from nuget manager
  2. My source code before necessary changes :

25-02-2022 18-36-01

  1. After my changes :

25-02-2022 18-36-29

Coradis commented 2 years ago

Full (small) project extract "as is" from the VS solution : (I assumed that you want the code with the problem)

wlx.addin.word.w2k.zip

manuelbl commented 2 years ago

Thanks a lot for the project files. This has helped me reproduce it and test the fix. It's a Word add-in (and not a regular application)!

You now have two options:

  1. Upgrade to version 3.0.2 of Codecrete.SwissQRBill.Generator and then selectively downgrade SkiaSharp to version 2.80.2

  2. Use the code from Microsoft Word Add-in example and in particular the code in the main add-in class plus the two classes SystemDrawingCanvas and MetafileCanvas. For this option, use the Codecrete.SwissQRBill.Core NuGet package (instead of Codecrete.SwissQRBill.Generator).

The advantage of option 2 is that it uses the EMF format (instead of PNG), which is resolution-independent and therefore of higher quality. Additionally, it does not require SkiaSharp and is thus smaller and quicker.

Coradis commented 2 years ago

Thank you very much for your time and speed in finding a solution. We chose the 2nd option and it does the job very well.

Do you think that the 2 classes SystemDrawingCanvas and MetafileCanvas could be included in the standard package ? or should they always be used outside? (just for information for us, we can handle them very well like that). Thanks again, we close this issue.

Best regards, Herve.

manuelbl commented 2 years ago

Thanks for the feedback. Glad to hear it has helped you.

I'm considering making it part of a NuGet package, but I haven't decided it yet. It's a Windows-only technology, so it would need to be in a separate package.

manuelbl commented 2 years ago

A new NuGet package Codecrete.SwissQRBill.Windows has been published. It includes the SystemDrawingCanvas and MetafileCanvas classes. Note that they are in different namespace (Codecrete.SwissQRBill.Windows instead of Codecrete.SwissQRBill.SystemDrawing).

Coradis commented 2 years ago

Thanks for information.