codebude/QRCoder

Sample code fails - "QRCode" doesn't exist

markdall opened this issue ยท 5 comments

Type of issue

[x ] Bug

Expected Behavior

Sample code from readme.md works in VS 2022 LTSC 17.6 / .NET 6.0

Sample code from readme.md:

QRCodeGenerator qrGenerator = new QRCodeGenerator();
QRCodeData qrCodeData = qrGenerator.CreateQrCode("The text which should be encoded.", QRCodeGenerator.ECCLevel.Q);
QRCode qrCode = new QRCode(qrCodeData);
Bitmap qrCodeImage = qrCode.GetGraphic(20);

Current Behavior

Severity	Code	Description	Project	File	Line	Suppression State
Error	CS0246	The type or namespace name 'QRCode' could not be found (are you missing a using directive or an assembly reference?

Possible Solution (optional)

QRCodeGenerator qrGenerator = new QRCodeGenerator();
QRCodeData qrCodeData = qrGenerator.CreateQrCode("The text which should be encoded.", QRCodeGenerator.ECCLevel.Q);
BitmapByteQRCode bitmapQRCode = new BitmapByteQRCode(qrCodeData);
File.WriteAllBytes("output.bmp", bitmapQRCode.GetGraphic(20));

Steps to Reproduce (for bugs)

Use the current sample code first found by starting at the top of the Readme.md file and scrolling down, in VS 2022. "QRCode" doesn't seem to exist anymore.

Your Environment

  • Version used: 1.4.3
  • Compiled from source or NuGet package?: NuGet
  • Payload/Encoded text: "The text which should be encoded."
  • Used payload generator: QRCodeGenerator
  • Used ECC-level: QRCodeGenerator.ECCLevel.Q
  • Used renderer class: Not sure what that is.
  • .NET 6.0

I'd make a pull request with my version that works (see: possible solution) but I'm not an actual developer and my solution may have everyone who reads it slapping their foreheads in dismay at my folly. I mostly just wanted to point out that the sample code doesn't work, likely because the name space or class name was changed.

This repo isn't really being maintained- most have success just using the prior release of v1.4.1. It appears to be more stable.

QRCode appears to have been removed. I changed my code to:

        var qrGenerator = new QRCodeGenerator();
        var qrCodeData = qrGenerator.CreateQrCode(text, QRCodeGenerator.ECCLevel.Q);
        var qrCode = new PngByteQRCode(qrCodeData);
        var qrCodeAsPngByteArr = qrCode.GetGraphic(20);

@melmullen @markdall This is actually better, as the old version provides a System.drawing.Bitmap. Which is already somewhat outdated and also limits us to the Windows platform. The new version gives us a byte array which we can use directly in skia etc.

@kenan-kajkus Sure, and the documentation ought to be updated to reflect how to use the library, instead of the old way that doesn't work.... right?

@markdall Sorry, I wasn't trying to excuse the lack of documentation. I just stumbled across this issue and wanted to explain why this change is an improvement despite breaking changes.