The following code is throwing null reference error from the line reader.ReadBarCodes()
. What’s strange is that this code works fine in most cases, but throws error only sometimes. In particular, when decoding PDF417. I am decoding only QR and PDF417 as you can see in the second method. Note, it is not that decoding PDF417 always throws error, but it is random.
public List<BarcodeResult> Decode(Stream stream)
{
var results = new List<BarcodeResult>();
using (var reader = CreateAsposeBarCodeReader(stream))
{
foreach (var result in reader.ReadBarCodes())
{
results.Add(new BarcodeResult
{
Value = result.CodeText,
Rectangle = result.Region.Rectangle
});
}
}
return results;
}
private BarCodeReader CreateAsposeBarCodeReader(Stream stream)
{
if (_barcodeSetting.RecognizePdf417 && _barcodeSetting.RecognizeQR)
return new BarCodeReader(stream, DecodeType.Pdf417, DecodeType.QR);
if (_barcodeSetting.RecognizePdf417)
return new BarCodeReader(stream, DecodeType.Pdf417);
if (_barcodeSetting.RecognizeQR)
return new BarCodeReader(stream, DecodeType.QR);
return new BarCodeReader(stream);
}
The stacktrace looks like this:
System.NullReferenceException
HResult=0x80004003
Message=Object reference not set to an instance of an object.
Source=Aspose.BarCode
StackTrace:
at Aspose.BarCode.BarCodeRecognition.BarCodeResult.(String )
at Aspose.BarCode.BarCodeRecognition.BarCodeResult..ctor( )
at . ()
Notice those strange symbols in the stacktrace. I have never seen anything like this:
image.png (12.4 KB)
I am using Aspose.BarCode for .NET v24.8.0.0 in a WPF application (.NET Framework 4.7.2).