Home > Enterprise >  QRCode' does not contain a definition for 'GetGraphic' and no accessible extension me
QRCode' does not contain a definition for 'GetGraphic' and no accessible extension me

Time:01-10

'QRCode' does not contain a definition for 'GetGraphic' and no accessible extension method 'GetGraphic' accepting a first argument of type 'QRCode' could be found (are you missing a using directive or an assembly reference?)

I am tying to Generate QR Code in .Net 6 I am found an error, Tell me Where is my code wrong?

QRCodeGenerator qrCodeGenerator = new();
string data = "Name : "   employeeSalaryGetDetails.Name   "\n DOB : "   employeeSalaryGetDetails.DayofBirth.ToString()   "\n Email Address : "   employeeSalaryGetDetails.EmailId.ToString();
QRCodeData qrCodeData = qrCodeGenerator.CreateQrCode(data, QRCodeGenerator.ECCLevel.Q);
QRCode qrCoder = new();
qrCoder.Equals(qrCodeData);
Image rqCodeImage = qrCoder.GetGraphic(20);

var bytes = ImageToByteArray(rqCodeImage);
return File(bytes, "image/tmp");

CodePudding user response:

It seems the package is incomplete for .NET6.0 and up, in a new project when I implement QRCoder straight from nuget and Include the using QRCoder. Type QRCode doesn't exist. The github has some open issues involving this issue. Downgrading to nuget version 1.4.2 might fix your problem.

I have tried it and it works. It would look like this:

using QRCoder;
using System.Drawing;

namespace ClassLibrary1;
public class Class1
{
    public void CreateQR()
    {
        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);
    }
}

Note: This is just an example

  • Related