NullReferenceException on GenerateBarCodeImage or Save()

Upgrading an old app to .net 4.7.2 using v20.3.0 of Aspose.Barcode

I am getting a NullReferenceException when trying to obtain the image. I even pulled in some code from the samples on github and still an issue. Anyone have any ideas on how to resovle? Thanks.

   protected byte[] EncodeBarCode(string BarCodeText)
    {

        BarcodeGenerator generator = new BarcodeGenerator(EncodeTypes.QR, "12345TEXT");

        // Set encoding mode, Auto for Micro QR, error correction level          
        generator.Parameters.Barcode.QR.QrEncodeMode = QREncodeMode.Auto;
        generator.Parameters.Barcode.QR.QrEncodeType = QREncodeType.Auto;
        generator.Parameters.Barcode.QR.QrErrorLevel = QRErrorLevel.LevelL;

        // Get barcode image Bitmap and Save QR code
        Bitmap lBmp = generator.GenerateBarCodeImage();  // <<== NULLREFEXCEPT

        MemoryStream xStream = new MemoryStream();
        lBmp.Save(xStream, System.Drawing.Imaging.ImageFormat.Png);

        return xStream.ToArray();
    }

@mvgibson,
I am afraid that no issue is observed and image is created successfully using above code with the latest version. Please share your environment details with us and also share a complete compilable console application solution for our testing which contains only this sample code.

BarcodeGenerator generator = new BarcodeGenerator(EncodeTypes.QR, "12345TEXT");

// Set encoding mode, Auto for Micro QR, error correction level          
generator.Parameters.Barcode.QR.QrEncodeMode = QREncodeMode.Auto;
generator.Parameters.Barcode.QR.QrEncodeType = QREncodeType.Auto;
generator.Parameters.Barcode.QR.QrErrorLevel = QRErrorLevel.LevelL;

// Get barcode image Bitmap and Save QR code
Bitmap lBmp = generator.GenerateBarCodeImage();  // <<== NULLREFEXCEPT

MemoryStream xStream = new MemoryStream();
lBmp.Save(xStream, System.Drawing.Imaging.ImageFormat.Png);

byte[] data = xStream.ToArray();
lBmp.Save(path + "output.png", System.Drawing.Imaging.ImageFormat.Png);

output.png (404 Bytes)

Thanks. I will put together a package.

I am experiencing the NullReferenceException for any samples when calling the GenerateBarCodeImage or Save functions . See attached image.

Visual Studio Enterprise 2019, Version 16.5.4; .net Framework 4.7.2; C#; Was a working asp.net project tuned to .net Framework 4.5. I updated the project properties to 4.7.2 and swapped out the standalone barcode.dll with the nuget package. Had to update to the latest api.

image.png (19.8 KB)

Ok, it must be my environment. I put together the attached console app and I am having the same nullreferenceexception. See Screenshot. It allows me to continue on through the Main() function and ultimately does produce the barcode.

image.png (36.8 KB)

When trying to upload the zip, i received an error that the file was too large.
image.png (3.4 KB)

solution is here
https://1drv.ms/u/s!AjSr--DxHgPpgp1cbv0VHVivP3KIXw?e=wH2ntL

Environment:
Windows 10 Pro for Workstations, v 1909;
x64;
Visual Studio Enterprise 2019, Version 16.5.4;
.net Framework 4.7.2;
C#;

Please let me know what else you need.

Thanks so much.
Mike

Ok. I was lucky enough to have a couple other developers handy this morning. The code worked on their end right away. So we stepped through all of the VS Debugging Options and found that I did not have “Just My Code” checked. Checking this solved my NullReferenceException error. They unchecked their options and received the error.

Just wanted to pass along the information just in case anyone ran into the same issue!

@mv_gibson,
This is strange as your solution is working fine here. I have VS 2019 and Windows 7. It seems to be some environment issue. You may please test this scenario on some other system and share your feedback. Also share the complete exception details with us for our reference.

Hi. Please see solution above. If you go to Debug | Options | General and uncheck “Enable Just My Code” in visual studio, then set a breakpoint in the function and step through, you will get the NullReferenceException.

@mv_gibson,
No difference is observed by checking/un-checking this option at my end. Please provide the complete exception detail for our reference.

I was able to recreate this experience exactly as described above. VS 2019

image.png (22.9 KB)

@Wolfeitz,
Please share the details from the button “Copy Details” and provide us. We will look into it and may log a ticket for investigation.

image.png (20.2 KB)

image.png (18.0 KB)

Ok found the problem. It only exists in Full debug mode of VS2019 (remove checkbox from Tools->Options->Debugging->General->Enable Just My Code).

Problem exists with internal codetext processing (internal exception which is caught in the code). Full debug mode tries to resolve this internal exception. Added fix, it will be provided in next month.

As workaround you can temporarily disable Full debug mode.

The issues you have found earlier (filed as BARCODENET-37437) have been fixed in Aspose.BarCode for .NET v20.4. This message was posted using Bugs notification tool by ahsaniqbalsidiqui