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

Base64QRCode does not exist in 1.4.3 #361

Closed
ScottyLightnin opened this issue Dec 13, 2021 · 17 comments
Closed

Base64QRCode does not exist in 1.4.3 #361

ScottyLightnin opened this issue Dec 13, 2021 · 17 comments
Labels

Comments

@ScottyLightnin
Copy link

Type of issue

[x] Bug
[ ] Question (e.g. about handling/usage)
[ ] Request for new feature/improvement

Expected Behavior

No build errors after minor upgrade of 1.4.2 to 1.4.3

Current Behavior

Upgrading my nuget package dependency from 1.4.2 to 1.4.3 caused build errors in my project, because Base64QRCode could not be found

Possible Solution (optional)

Looks to be related to NET6_0_WINDOWS directives that have been added in this release

Steps to Reproduce (for bugs)

  1. .Net 6 Web App.
  2. Add 1.4.2 QRCoder package
  3. Instantiate a Base64QRCode
  4. Compile / Run and observe no build error
  5. Upgrade to 1.4.3 package
  6. Attempt to build solution. Compiler error: The type or namespace name 'Base64QRCode' could not be found (are you missing a using directive or an assembly reference?)

Your Environment

TargetOS of Web App: None.
By explicitly setting this to Windows, the compiler error is fixed, but this breaking change shouldn't be introduced in a patch level version change.

@DUWENINK
Copy link

QRCode does not exist tooooooooooooooooooooooooooooooooo

@LuohuaRain
Copy link

Just use

Convert.ToBase64String(qrCodeByte)

@LuohuaRain
Copy link

LuohuaRain commented Dec 13, 2021

QRCode does not exist tooooooooooooooooooooooooooooooooo

use specific constructor, such as PngByteQRCode(), AsciiQRcode(), BitmapByteQRCode()

@codebude
Copy link
Owner

codebude commented Dec 13, 2021

Hello @ScottyLightnin ,

this is not bug in QRCoder but more the consequence of breaking changes in Microsoft .NET 6.0.

Explanation - Why are some renderers missing

Up to QRCoder 1.4.2 there was no explicit compilation target for .NET6, thus when apps (that target .NET 6.0) used QRCoder, the package manager/Visual Studio picked the .NET 5.0 binaries when choosing the nearest framework binary. The .NET 5.0 binaries support System.Drawing and thus contain rendering classes like the Base64QRCode which makes use of System.Drawing.

Unfortunately not having .NET 6 as target in QRCoder lead to some serious trouble (see #354, #353) because not everything that works in .NET 5.0 also works in .NET 6.0 or in other words not all binaries/libraries to be available in .NET 5.0 can be expected available on .NET 6.0. Thus it was only consequent to add .NET 6.0 as target frameworks. I think you're right up to this point?

With adding net6.0 and net6.0-windows as targets, I had to remove the System.Drawing-based renderers for the target net6.0, because Microsoft official says, that System.Drawing from .NET 6.0 on only will be available on Windows platforms: https://docs.microsoft.com/en-us/dotnet/core/compatibility/core-libraries/6.0/system-drawing-common-windows-only

TL;DR: It was not my decision to remove the System.Drawing-based renderers from net6.0 target, but I was simply following the breaking changes in .NET 6.0/System.Drawing (as described in the link above).

What can you do now?

You have multiple options:

  • Target your application to net6.0-windows as the renderes like Base64QRCode or QRCode are available there.
  • Use PngByteQRCode or BitmapByteQRCode. They return the QR Code image as byte array. Then simply pass the bytes to Convert.ToBase64String(...) to receive the same output as for Base64QRCode.
  • Stick with QRCoder 1.4.2 which hasn't the targets for net6.0 and thus via fallback to net5.0 allows you to use Base64QRCode. (The only difference between 1.4.2 and 1.4.3 are the new net6.0 targets as can be seen here: https://github.com/codebude/QRCoder/wiki/Release-notes )

Mid-term solution

Mid-term we will move QRCoder from System.Drawing to ImageSharp, because System.Drawing became a pain in the *** over the years. By replacing it with an alternative graphics lib (currently we aim to ImageSharp) we hope to gain wider support for the different platforms.
Note: Since this will bring a lot of breaking changes, this will be released as QRCoder 2.X.X

@codebude
Copy link
Owner

Afterthought: I stand by the above changes. The only point where I can understand your displeasure @ScottyLightnin is that these (breaking) changes came with version 1.4.3 and not with a 2.0.0. It should be noted that the QRCoder has always increased the version number by one digit with each release (see here). According to strict/clean semantic versioning the 1.4.3 should have been a 2.0.0. I can see that. For the future (also with regard to QRCoder 2.X.X) I plan to increase the version numbers cleanly/according to semantic versioning.

@ScottyLightnin
Copy link
Author

Great explanations, thank you @codebude , and yes, you got my main point was that I wasn't expecting a breaking change with the version change from 1.4.2 > 1.4.3. I've already been able to work around the problem (by targeting net6.0-windows), it was just unexpected since I've grown accustomed to semantic versioning.
Thanks again for your work, and your detailed explanation. Much appreciated.

@joeangry
Copy link

joeangry commented Dec 18, 2021

Having breaking changes in a minor patch seems strange to me to be honest, I had no idea why my code stopped working when I updated from 1.4.1 to 1.4.3.

Otherwise great library!

@mhosman
Copy link

mhosman commented Dec 19, 2021

How to pass foreground and background now with PngByteQrCode when we get graphic?

@codebude
Copy link
Owner

@mhosman either stick to QRCoder 1.4.2 since 1.4.3 added only the explicit targets to net 6.0 or wait for QRCoder 2.0.0 which will be based on ImageSharp and thus support the full renderer stack again.

@FedericoBernardi
Copy link

Any time frame for version 2.0

@olmobrutall
Copy link

olmobrutall commented Feb 18, 2022

On thing that I don't understant.... I'm working with 1.4.1 and .Net Core 6 in docker, and as long as I use this:

FROM base AS final
WORKDIR /app
RUN apt-get update && apt-get install -y libgdiplus
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "OfficeControl.React.dll"]

Looks like System.Drawing is workin OK in a linux environment.

If I use System.Drawing directly you need to supress the warning, but that's ok for me:

#pragma warning disable CA1416 // Validate platform compatibility
            Graphics a = Graphics.FromHwnd((IntPtr)2);
#pragma warning restore CA1416 // Validate platform compatibility

@rgomez90
Copy link

rgomez90 commented Feb 21, 2022

On thing that I don't understant.... I'm working with 1.4.1 and .Net Core 6 in docker, and as long as I use this:

FROM base AS final
WORKDIR /app
RUN apt-get update && apt-get install -y libgdiplus
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "OfficeControl.React.dll"]

Looks like System.Drawing is workin OK in a linux environment.

If I use System.Drawing directly you need to supress the warning, but that's ok for me:

#pragma warning disable CA1416 // Validate platform compatibility
            Graphics a = Graphics.FromHwnd((IntPtr)2);
#pragma warning restore CA1416 // Validate platform compatibility

@olmobrutall that works because you are using net5.0 not net6.0.

So you just have to have libgdiplus installed in Linux and that's all.

With version 1.4.3 you would get a runtime exception like seen here.
You can "workaround" this by setting the System.Drawing.EnableUnixSupport runtime config switch to true like written here

@stsrki
Copy link

stsrki commented Nov 4, 2022

@codebude Would you consider a PR that includes code from https://github.com/smack0007/ImageDotNet and integrates it into QRCoder? From what I can see by a glance at their code, it might be a good fallback for NET6 and PNG support. I know that ImageDotNet is no longer active, but if it works, it works. It is better than relying on much larger libraries like ImageSharp and SkiaSharp.

@OptimusPi
Copy link

FYI: https://security.snyk.io/vuln/SNYK-DOTNET-SYSTEMDRAWINGCOMMON-3063427

@brz
Copy link

brz commented Mar 20, 2023

I would stay away from ImageSharp as that library now has licensing fees in certain environments:
https://github.com/SixLabors/ImageSharp/blob/main/LICENSE

A better alternative would be SkiaSharp or Magick.NET

@samsar777
Copy link

Great library. Can we expect aforementioned mid-term solution to replace the System.Drawing?

@Shane32
Copy link
Contributor

Shane32 commented Apr 13, 2024

Fixed by:

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

No branches or pull requests