IronBarCode Could Not Recognize MSI Barcode

This article was translated from English: Does it need improvement?
Translated
View the article in English

Problem

When creating an MSI barcode using the IronBarCode library, there are instances where the BarcodeReader.Read method is unable to read the generated MSI barcode, resulting in an empty scan and the expected value from the barcode.

Solution

To ensure that the BarcodeReader.Read can read the MSI barcode, we must provide the secondary optional BarcodeReaderOptions parameter for the Read method. Within the BarcodeReaderOptions, we explicitly specify the barcode type that we are trying to read by assigning the value ExpectedBarcodeTypes. This way, the Read method would recognize the MSI barcode generated from IronBarCode as well as any external MSI barcodes.

Below is a quick example of how to apply BarcodeReaderOptions to BarcodeReader.Read.

Code Example

// Creating MSI Barcode with the value "12345"
var myBarcode = BarcodeWriter.CreateBarcode("12345", BarcodeWriterEncoding.MSI);

// Save barcode as image
myBarcode.SaveAsImage("msi.png");

// Reading MSI
var barcodeReaderOptions = new BarcodeReaderOptions
{
     // Assigning BarcodeEncoding.MSI to ExpectBarcodeType to ensure that IronBarcode expects MSI type barcodes specifically 
  ExpectBarcodeTypes = BarcodeEncoding.MSI,
};

// Read barcode with additional barcodeReaderOptions from above
var barcodeResults = BarcodeReader.Read("msi.png", barcodeReaderOptions);

// Using a for loop and print out the result 
foreach (BarcodeResult result in barcodeResults)
{
  Console.WriteLine(result.Text);
    // Output: 12345 
}
// Creating MSI Barcode with the value "12345"
var myBarcode = BarcodeWriter.CreateBarcode("12345", BarcodeWriterEncoding.MSI);

// Save barcode as image
myBarcode.SaveAsImage("msi.png");

// Reading MSI
var barcodeReaderOptions = new BarcodeReaderOptions
{
     // Assigning BarcodeEncoding.MSI to ExpectBarcodeType to ensure that IronBarcode expects MSI type barcodes specifically 
  ExpectBarcodeTypes = BarcodeEncoding.MSI,
};

// Read barcode with additional barcodeReaderOptions from above
var barcodeResults = BarcodeReader.Read("msi.png", barcodeReaderOptions);

// Using a for loop and print out the result 
foreach (BarcodeResult result in barcodeResults)
{
  Console.WriteLine(result.Text);
    // Output: 12345 
}
' Creating MSI Barcode with the value "12345"
Dim myBarcode = BarcodeWriter.CreateBarcode("12345", BarcodeWriterEncoding.MSI)

' Save barcode as image
myBarcode.SaveAsImage("msi.png")

' Reading MSI
Dim barcodeReaderOptions As New BarcodeReaderOptions With {.ExpectBarcodeTypes = BarcodeEncoding.MSI}

' Read barcode with additional barcodeReaderOptions from above
Dim barcodeResults = BarcodeReader.Read("msi.png", barcodeReaderOptions)

' Using a for loop and print out the result 
For Each result As BarcodeResult In barcodeResults
  Console.WriteLine(result.Text)
	' Output: 12345 
Next result
$vbLabelText   $csharpLabel

In the example, we first instantiate a new BarcodeReaderOptions variable and then assign ExpectedBarcodeTypes with the BarcodeEncoding.MSI enum, instructing IronBarcode to expect the MSI barcode instead. Afterwards, we print out the value of the barcode, which would be 12345, in a for loop as the barcodeResults returns an array of BarcodeResults and loop through each result for the text value.

Curtis Chau
Escritor Técnico

Curtis Chau tiene una licenciatura en Ciencias de la Computación (Carleton University) y se especializa en el desarrollo front-end con experiencia en Node.js, TypeScript, JavaScript y React. Apasionado por crear interfaces de usuario intuitivas y estéticamente agradables, disfruta trabajando con frameworks modernos y creando manuales bien ...

Leer más
¿Listo para empezar?
Nuget Descargas 1,935,276 | Versión: 2025.11 recién lanzado