QRCoder icon indicating copy to clipboard operation
QRCoder copied to clipboard

Type or namespace "QRCode" could not be found in new Blazor Server .Net 6 App

Open brentminder opened this issue 3 years ago • 10 comments

Type of issue

[X] Bug

Expected Behavior

I'm trying your sample code for QRCoder, and the "QRCode" reference in the code should be found from the using statement: @using QRCoder ... QRCode qrCode = new QRCode(qrCodeData);

Current Behavior

I'm getting type or namespace" QRCode "could not be found in a brand new Blazor Server .Net 6 app using your sample code: @using QRCoder ... QRCode qrCode = new QRCode(qrCodeData);

Steps to Reproduce (for bugs)

Create a blazor server app and paste this code into the index.razor page:

@page "/"
@using QRCoder
@using System.Drawing
<h1>Hello, world!</h1>
@code {
    protected async override Task OnInitializedAsync()
    {
	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);
	await base.OnInitializedAsync();
    }
}

Your Environment

VS 2022 latest Nuget QRCoder latest: <PackageReference Include="QRCoder" Version="1.4.3" /> .NET 6 Blazor Server

brentminder avatar Jan 15 '22 00:01 brentminder

I have the same problem in version 1.4.3 and use .NET 6

2014fighting avatar Jan 16 '22 04:01 2014fighting

I having the same problem in version 1.4.3 and .NET 6. So I downgraded to 1.4.2. Reference: #361

wengtad avatar Jan 17 '22 04:01 wengtad

Same here, I had to downgrade.

alstan avatar Jan 18 '22 02:01 alstan

I experienced the same when upgrading my class lib to .NET 6. Was able to make it work by setting Target OS to Windows on project settings but I would prefer not having to do this, if possible.

heidgert avatar Jan 20 '22 12:01 heidgert

Here explanations and possible solutions.

https://github.com/codebude/QRCoder/issues/361#issuecomment-992152570

cyberdarius avatar Jan 20 '22 13:01 cyberdarius

Same here.

Anduin2017 avatar Mar 27 '22 06:03 Anduin2017

I having the same problem in version 1.4.3 and .NET 6. So I downgraded to 1.4.2. Reference: #361

Work for me by downgrading the version to the 1.4.2

Strudus avatar Apr 18 '22 14:04 Strudus

You can try:

PngByteQrCode OR BitmapByteQrCode

1973-clinton avatar Mar 13 '23 14:03 1973-clinton

For those wondering how to display a QR code in Blazor WASM using .NET 6+, you might want to try this:

@using QRCoder

<img src=@("data:image/png;base64," + System.Convert.ToBase64String(
 PngByteQRCodeHelper.GetQRCode("text you want displayed as QR code", QRCodeGenerator.ECCLevel.Q, 10))) />

philipp-koch avatar Aug 22 '23 22:08 philipp-koch

For those wondering how to display a QR code in Blazor WASM using .NET 6+, you might want to try this:

@using QRCoder

<img src=@("data:image/png;base64," + System.Convert.ToBase64String(
 PngByteQRCodeHelper.GetQRCode("text you want displayed as QR code", QRCodeGenerator.ECCLevel.Q, 10))) />

after downgrading to 1.4.2, this inline code worked, thanks for the suggestion

AmeerIT avatar Dec 23 '23 22:12 AmeerIT