[Solved] ASP.Net Error: The type name QRCode does not exist in the type QRCodeGenerator

clonekoadi
 
on Jun 09, 2021 10:14 PM
1020 Views

Hi

I have read this article and I tried to test it, but i get this error 

The type name 'QRCode' does not exist in the type 'QRCode Generator'

Generate QR Code in Crystal Report using C# and VB.Net in ASP.Net

here the code where i encounter it

Thanks

private byte[] GenerateQrCode(string qrmsg)
{
    string code = qrmsg;
    QRCodeGenerator qrGenerator = new QRCodeGenerator();
    QRCodeGenerator.QRCode qrCode = qrGenerator.CreateQrCode(code, QRCodeGenerator.ECCLevel.Q);
    System.Web.UI.WebControls.Image imgBarCode = new System.Web.UI.WebControls.Image();
    imgBarCode.Height = 150;
    imgBarCode.Width = 150;
    using (Bitmap bitMap = qrCode.GetGraphic(20))
    {
        using (MemoryStream ms = new MemoryStream())
        {
            bitMap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
            byte[] byteImage = ms.ToArray();
            return byteImage;
        }
    }
}
Download FREE API for Word, Excel and PDF in ASP.Net: Download
dharmendr
 
on Jun 09, 2021 10:34 PM
on Jun 09, 2021 10:35 PM
clonekoadi says:
QRCodeGenerator qrGenerator = new QRCodeGenerator();
QRCodeGenerator.QRCode qrCode = qrGenerator.CreateQrCode(code, QRCodeGenerator.ECCLevel.Q);

Change above code with below.

QRCodeGenerator qrGenerator = new QRCodeGenerator();
QRCodeData qrCodeData = qrGenerator.CreateQrCode(code, QRCodeGenerator.ECCLevel.Q);
QRCode qrCode = new QRCode(qrCodeData);

Updated code.

private byte[] GenerateQrCode(string qrmsg)
{
    string code = qrmsg;
    QRCodeGenerator qrGenerator = new QRCodeGenerator();
    QRCodeData qrCodeData = qrGenerator.CreateQrCode(code, QRCodeGenerator.ECCLevel.Q);
    QRCode qrCode = new QRCode(qrCodeData);
    System.Web.UI.WebControls.Image imgBarCode = new System.Web.UI.WebControls.Image();
    imgBarCode.Height = 150;
    imgBarCode.Width = 150;
    using (Bitmap bitMap = qrCode.GetGraphic(20))
    {
        using (MemoryStream ms = new MemoryStream())
        {
            bitMap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
            byte[] byteImage = ms.ToArray();
            return byteImage;
        }
    }
}