We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Index was outside the bounds of the array (BarcodeReader.Read())

I'm using the latest version of the Aspose.BarCodeRecognition dll ( for the .net framework 4.0 for C# (released 8/01/2011). I'm attempting to read a 2D barcode (PDF417) from a PDF that I created using Aspose.BarCode. When I hit the line of code that calls the Read() method from the BarCodeRecognition.BarCodeReader object, I get this error "Index was outside the bounds of the array." I also get this error when I try to use the demo barcode reader on the Aspose website (http://www.aspose.com/demos/.net-components/aspose.barcode/csharp/barcode-reader/read-from-pdf.aspx).

Please help...

I have attached the PDF file in question. Also, here is a code snipped from my application:

MemoryStream ms = new MemoryStream();
if (extractor.GetNextImage(ms))
ms.Position = 0;

BarCodeReader reader = new BarCodeReader(ms, BarCodeReadType.Pdf417);
while (reader.Read())


Thank you for inquiry.

This is happening due to the images that are passed to the BarCodeReader, some of those have 2x2 dimension that do not contain any barcode. As a workaround, could you please wrap the Read() method in a separate try catch block? It worked at my end with the following code.

// bind the pdf
PdfExtractor extractor = new PdfExtractor();
Console.WriteLine(“Extracting images…”);
int i = 1;
// save images to stream in a loop
while (extractor.HasNextImage())
Console.WriteLine(“Getting next image…”);
// save to stream
MemoryStream stream = new MemoryStream();
stream.Position = 0;
Console.WriteLine(“Recognizing barcode…” + i);
// recognize the barcode from the image stream above
BarCodeReader reader = new BarCodeReader(stream, BarCodeReadType.Pdf417);
while (reader.Read())
Console.WriteLine("Symbology: " + reader.GetReadType() + " == Codetext: " + reader.GetCodeText());
catch (Exception ex)
Console.WriteLine("Error reading barcode: " + ex.Message);

Hi Saqib,

Thanks for your reply.

Just so we're clear...are you asking me to "eat" the exception and allow the extractor to keep processing?


This is a bug (ID: 29718), to throw IndexOutofBounds exception on some of the extracted images, which would be fixed by us. Please use the above solution as a workaround until the issue gets resolved.

The issues you have found earlier (filed as BARCODENET-29718) have been fixed in this update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.