QRCoder icon indicating copy to clipboard operation
QRCoder copied to clipboard

QRCode class not found after updating from `1.4.2 to 1.6.0`

Open badrshs opened this issue 1 year ago • 4 comments

Type of issue

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

Expected Behavior

The QRCode class should be found and usable after updating to the latest version of QRCoder 1.4.2 -> 1.6.0. The following code should compile and work as it did with previous versions:

using var qrCode = new QRCode(qrCodeData);

Current Behavior

After updating to the latest version of QRCoder, the QRCode class can no longer be found. The compiler throws an error:

Error (active) CS0246 The type or namespace name 'QRCode' could not be found (are you missing a using directive or an assembly reference?)

This is breaking existing code that was working fine with previous versions 1.4.2.

Steps to Reproduce (for bugs)

  1. Update QRCoder to the latest version
  2. Use the following code:
using System.Drawing;
using X.Core.Services;
using QRCoder;

namespace X.Services;

public class QrCodeGenerator : IQrCodeGenerator
{
    public Bitmap GenerateQrCode(string text) => GenerateQrCode(text, 10);

    private Bitmap GenerateQrCode(string text, int size)
    {
        using var qrGenerator = new QRCodeGenerator();
        QRCodeData qrCodeData = qrGenerator.CreateQrCode(text, QRCodeGenerator.ECCLevel.Q);
        using var qrCode = new QRCode(qrCodeData); // Error occurs here
        return qrCode.GetGraphic(size);
    }
}

Your Environment

  • Version used: 1.6.0
  • Compiled from source or NuGet package?: NuGet package
  • Used payload generator: QRCodeGenerator
  • Environment net8.0

Additional context:

  • Operating System: Windows
  • This code was working fine until the update from 1.4.2 -to 1.6.0.

badrshs avatar Sep 17 '24 10:09 badrshs

after some search I was able to fix this by doing

[SuppressMessage("Interoperability", "CA1416:Validate platform compatibility")]
private Bitmap GenerateQrCode(string text, int size)
{
    using var qrGenerator = new QRCodeGenerator();
    using QRCodeData qrCodeData = qrGenerator.CreateQrCode(text, QRCodeGenerator.ECCLevel.Q);
    using var qrCode = new PngByteQRCode(qrCodeData);
    byte[] qrCodeAsPngByteArr = qrCode.GetGraphic(size);

    using var ms = new MemoryStream(qrCodeAsPngByteArr);
    return new Bitmap(ms);
}

badrshs avatar Sep 17 '24 11:09 badrshs

This is still existing as of June 2025, on .NET 8.0. Notably, this doesn't impact legacy .NET Framework 4.8 projects.

Also, the workaround attribute decoration provided above does not work if generating a base QRCode class. It does work with the PngByteQRCode class as shown, but it seems the PngByteQRCode class works without the SuppressMessage attribute.

mbaker-e2open avatar Jun 12 '25 18:06 mbaker-e2open

As far as I know, @codebude does not intend to make changes to have the QRCode class support .NET 8 without specifically targeting net8-windows. (Other renderers can be used, but not those based on System.Drawing.)

See this link for details:

  • https://github.com/codebude/QRCoder/wiki/Advanced-usage---QR-Code-renderers

The long-term goal is for v2.x to have multiple nuget packages to target different rendering engines. See:

  • #512

Shane32 avatar Jun 12 '25 18:06 Shane32

As far as I know, @codebude does not intend to make changes to have the QRCode class support .NET 8 without specifically targeting net8-windows. (Other renderers can be used, but not those based on System.Drawing.)

I realized after the fact that targeting JUST net8.0 instead of net8.0-windows was the issue. I assume this is due to graphics API access. Please disregard.

mbaker-e2open avatar Jun 13 '25 01:06 mbaker-e2open

Closing in favor of:

  • #489

Shane32 avatar Oct 02 '25 02:10 Shane32