Type or namespace "QRCode" could not be found in new Blazor Server .Net 6 App
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
I have the same problem in version 1.4.3 and use .NET 6
I having the same problem in version 1.4.3 and .NET 6. So I downgraded to 1.4.2. Reference: #361
Same here, I had to downgrade.
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.
Here explanations and possible solutions.
https://github.com/codebude/QRCoder/issues/361#issuecomment-992152570
Same here.
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
You can try:
PngByteQrCode OR BitmapByteQrCode
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))) />
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