Migrating from Google ML Kit Barcode Scanning to IronBarcode
This guide is for teams in one of two situations: you are porting an Android application to .NET MAUI or .NET 9 and need to replace ML Kit's barcode scanner with a managed alternative, or you were recommended Google ML Kit in a cross-platform barcode discussion and discovered - when you went to add the NuGet package - that it does not exist.
Google ML Kit Barcode Scanning is a native Android and iOS library. It ships as a Maven dependency (com.google.mlkit:barcode-scanning:17.3.0 bundled, or com.google.android.gms:play-services-mlkit-barcode-scanning:18.3.1 unbundled) for Kotlin/Java and as a CocoaPod (GoogleMLKit/BarcodeScanning) for Swift. ML Kit has been a standalone product since June 2020 and no longer requires Firebase, but there is no official .NET SDK, no dotnet add package google-mlkit-barcode, and no first-party C# API from Google. Community-maintained Xamarin/MAUI bindings have appeared over the years but they break when ML Kit updates its underlying SDK.
IronBarcode is a native .NET library that installs from NuGet, integrates with standard .NET patterns, and runs on Windows, Linux, macOS, Docker, Azure, and AWS. This guide shows how to translate the patterns you wrote in Kotlin or Java into equivalent C# code.
The Porting Context
When porting from ML Kit to IronBarcode, a few things change structurally - not just syntactically:
Callbacks become return values. ML Kit uses Android's Task API with addOnSuccessListener and addOnFailureListener. IronBarcode's BarcodeReader.Read() returns a collection synchronously. You iterate it directly. No callback registration, no thread coordination.
No scanner object. ML Kit requires you to build a BarcodeScannerOptions object, call BarcodeScanning.getClient(options) to get a scanner instance, then call scanner.process(inputImage). IronBarcode uses static methods - BarcodeReader.Read() is the entry point. There is no instance to manage or dispose.
No InputImage construction. ML Kit's InputImage must be constructed from an Android-specific source: InputImage.fromFilePath(context, uri), InputImage.fromBitmap(bitmap, rotation), or InputImage.fromMediaImage(image, rotation). IronBarcode accepts a file path string, a Stream, a byte[], or a System.Drawing.Bitmap. No Android context, no URI, no rotation metadata.
No Google Play Services. The unbundled ML Kit model runs through Google Play Services. The bundled variant ships the model inside the APK (adding roughly 2.4 MB) and avoids the Play Services check, but neither variant is available on .NET targets. IronBarcode has no such dependency - it runs identically on any platform .NET supports.
Quick Setup in .NET
Remove any Xamarin/MAUI ML Kit binding packages if they exist in your project, then install IronBarcode:
Add the license key at application startup - in Program.cs, MauiProgram.cs, or Startup.cs depending on your app type:
// NuGet: dotnet add package BarCode
using IronBarCode;
IronBarCode.License.LicenseKey = "YOUR-LICENSE-KEY";Imports IronBarCode
IronBarCode.License.LicenseKey = "YOUR-LICENSE-KEY"The license can be set at any point before the first BarcodeReader.Read() or BarcodeWriter.CreateBarcode() call. A free trial is available; trial mode watermarks generated barcodes but does not restrict reading.
Reading Barcodes: Kotlin to C#
Basic Single-Barcode Read
Here is a typical ML Kit read in Kotlin, scanning a single QR code from a file URI:
// Android Kotlin — ML Kit
val options = BarcodeScannerOptions.Builder()
.setBarcodeFormats(Barcode.FORMAT_QR_CODE)
.build()
val scanner = BarcodeScanning.getClient(options)
val inputImage = InputImage.fromFilePath(context, imageUri)
scanner.process(inputImage)
.addOnSuccessListener { barcodes ->
val barcode = barcodes.firstOrNull()
if (barcode != null) {
Log.d("MLKit", "Value: ${barcode.rawValue}")
Log.d("MLKit", "Format: ${barcode.format}")
}
}
.addOnFailureListener { e ->
Log.e("MLKit", "Scan failed: ${e.message}")
}
The equivalent in C# with IronBarcode:
using IronBarCode;
try
{
var results = BarcodeReader.Read("captured-image.jpg");
var barcode = results.FirstOrDefault();
if (barcode != null)
{
Console.WriteLine($"Value: {barcode.Value}");
Console.WriteLine($"Format: {barcode.Format}");
}
}
catch (Exception ex)
{
Console.WriteLine($"Scan failed: {ex.Message}");
}Imports IronBarCode
Try
Dim results = BarcodeReader.Read("captured-image.jpg")
Dim barcode = results.FirstOrDefault()
If barcode IsNot Nothing Then
Console.WriteLine($"Value: {barcode.Value}")
Console.WriteLine($"Format: {barcode.Format}")
End If
Catch ex As Exception
Console.WriteLine($"Scan failed: {ex.Message}")
End TryThe result is available immediately as a return value. barcode.Value corresponds to barcode.rawValue. barcode.Format corresponds to barcode.format. Error handling uses standard try/catch instead of a separate failure listener.
Multi-Barcode Read
ML Kit scans a single InputImage and returns a list. For multiple barcodes in one image, you iterate the success listener's list:
// Android Kotlin — ML Kit, multiple barcodes
val options = BarcodeScannerOptions.Builder()
.setBarcodeFormats(Barcode.FORMAT_ALL_FORMATS)
.build()
val scanner = BarcodeScanning.getClient(options)
val inputImage = InputImage.fromFilePath(context, imageUri)
scanner.process(inputImage)
.addOnSuccessListener { barcodes ->
for (barcode in barcodes) {
val rawValue = barcode.rawValue
val format = barcode.format
processBarcode(rawValue, format)
}
}
.addOnFailureListener { e -> Log.e("MLKit", e.message ?: "Unknown error") }
With IronBarcode, set ExpectMultipleBarcodes = true in BarcodeReaderOptions and iterate the result collection:
using IronBarCode;
var options = new BarcodeReaderOptions
{
Speed = ReadingSpeed.Balanced,
ExpectMultipleBarcodes = true
};
var results = BarcodeReader.Read("warehouse-shelf.jpg", options);
foreach (var barcode in results)
{
Console.WriteLine($"Format: {barcode.Format}, Value: {barcode.Value}");
ProcessBarcode(barcode.Value, barcode.Format);
}Imports IronBarCode
Dim options As New BarcodeReaderOptions With {
.Speed = ReadingSpeed.Balanced,
.ExpectMultipleBarcodes = True
}
Dim results = BarcodeReader.Read("warehouse-shelf.jpg", options)
For Each barcode In results
Console.WriteLine($"Format: {barcode.Format}, Value: {barcode.Value}")
ProcessBarcode(barcode.Value, barcode.Format)
NextFormat Specification: setBarcodeFormats to BarcodeReaderOptions
ML Kit requires you to specify which formats to look for via setBarcodeFormats(). If you omit it, ML Kit searches all formats. IronBarcode works the same way - omitting format constraints searches everything, but specifying expected types improves performance.
| ML Kit Kotlin | IronBarcode C# |
|---|---|
Barcode.FORMAT_QR_CODE | BarcodeEncoding.QRCode |
Barcode.FORMAT_CODE_128 | BarcodeEncoding.Code128 |
Barcode.FORMAT_CODE_39 | BarcodeEncoding.Code39 |
Barcode.FORMAT_CODE_93 | BarcodeEncoding.Code93 |
Barcode.FORMAT_EAN_13 | BarcodeEncoding.EAN13 |
Barcode.FORMAT_EAN_8 | BarcodeEncoding.EAN8 |
Barcode.FORMAT_UPC_A | BarcodeEncoding.UPCA |
Barcode.FORMAT_UPC_E | BarcodeEncoding.UPCE |
Barcode.FORMAT_PDF417 | BarcodeEncoding.PDF417 |
Barcode.FORMAT_DATA_MATRIX | BarcodeEncoding.DataMatrix |
Barcode.FORMAT_AZTEC | BarcodeEncoding.Aztec |
Barcode.FORMAT_ITF | BarcodeEncoding.ITF |
Barcode.FORMAT_CODABAR | BarcodeEncoding.Codabar |
Barcode.FORMAT_ALL_FORMATS | Omit ExpectBarcodeTypes |
Using format flags in IronBarcode:
using IronBarCode;
var options = new BarcodeReaderOptions
{
Speed = ReadingSpeed.Balanced,
ExpectMultipleBarcodes = true,
ExpectBarcodeTypes = BarcodeEncoding.QRCode | BarcodeEncoding.Code128 | BarcodeEncoding.EAN13
};
var results = BarcodeReader.Read("product-image.jpg", options);Imports IronBarCode
Dim options As New BarcodeReaderOptions With {
.Speed = ReadingSpeed.Balanced,
.ExpectMultipleBarcodes = True,
.ExpectBarcodeTypes = BarcodeEncoding.QRCode Or BarcodeEncoding.Code128 Or BarcodeEncoding.EAN13
}
Dim results = BarcodeReader.Read("product-image.jpg", options)The bitwise OR combination works the same way as ML Kit's vararg format list.
Result Access: rawValue and format
ML Kit's result object exposes rawValue (a String?) and format (an Int constant). IronBarcode's result exposes Value (a string) and Format (a BarcodeEncoding enum value).
// ML Kit Kotlin — result fields
val rawValue: String? = barcode.rawValue
val format: Int = barcode.format
val boundingBox: Rect? = barcode.boundingBox
val displayValue: String? = barcode.displayValue
// IronBarcode C# — result fields
string value = barcode.Value;
BarcodeEncoding format = barcode.Format;
int page = barcode.PageNumber; // populated for PDF / multi-page input' IronBarcode VB.NET — result fields
Dim value As String = barcode.Value
Dim format As BarcodeEncoding = barcode.Format
Dim page As Integer = barcode.PageNumber ' populated for PDF / multi-page inputbarcode.Value is always a non-null string in IronBarcode - if the read succeeded, the value is present. barcode.Format is the BarcodeEncoding enum member, which you can compare directly: if (barcode.Format == BarcodeEncoding.QRCode).
What's Different in .NET
Synchronous API instead of callbacks. This is the most significant structural change. ML Kit's scanner.process() returns a Task<List<Barcode>> in Android's sense - you chain listeners. IronBarcode's BarcodeReader.Read() returns the result inline. If you need to run it off the UI thread in a MAUI app, wrap it in Task.Run():
using IronBarCode;
// In a MAUI ViewModel or page code-behind
var results = await Task.Run(() => BarcodeReader.Read(imagePath));
foreach (var barcode in results)
{
// update UI on main thread
MainThread.BeginInvokeOnMainThread(() =>
{
ResultLabel.Text = barcode.Value;
});
}Imports IronBarCode
Imports System.Threading.Tasks
Imports Microsoft.Maui.Dispatching
' In a MAUI ViewModel or page code-behind
Dim results = Await Task.Run(Function() BarcodeReader.Read(imagePath))
For Each barcode In results
' update UI on main thread
MainThread.BeginInvokeOnMainThread(Sub()
ResultLabel.Text = barcode.Value
End Sub)
NextNo context parameter. Every ML Kit call that constructs an InputImage requires an Android Context. IronBarcode needs only a file path or stream. Removing context threading from barcode logic simplifies the code considerably.
No Google Play Services. The standard ML Kit model runs through Play Services - BarcodeScanning.getClient() checks Play Services availability at runtime and throws if unavailable. IronBarcode has no runtime service check. It either reads the image or throws a standard exception.
Standard exception handling. ML Kit's addOnFailureListener receives a Java Exception subclass. In .NET, failures surface as standard System.Exception throws, catchable with try/catch in the normal way.
Reading from PDF Documents
ML Kit has no PDF support. InputImage.fromFilePath() with a .pdf URI either fails or reads only the first page as a rasterized image, depending on the Android version. If your porting scenario involves documents - invoice processing, logistics manifests, form scanning - IronBarcode handles PDFs natively:
using IronBarCode;
// Read all barcodes from all pages of a PDF
var options = new BarcodeReaderOptions
{
Speed = ReadingSpeed.Balanced,
ExpectMultipleBarcodes = true
};
var results = BarcodeReader.Read("invoice-batch.pdf", options);
foreach (var barcode in results)
{
Console.WriteLine($"Page {barcode.PageNumber}: {barcode.Format} — {barcode.Value}");
}Imports IronBarCode
' Read all barcodes from all pages of a PDF
Dim options As New BarcodeReaderOptions With {
.Speed = ReadingSpeed.Balanced,
.ExpectMultipleBarcodes = True
}
Dim results = BarcodeReader.Read("invoice-batch.pdf", options)
For Each barcode In results
Console.WriteLine($"Page {barcode.PageNumber}: {barcode.Format} — {barcode.Value}")
NextNo image extraction step, no third-party PDF library, no page-iteration loop with separate rendering. Pass the PDF path, get all barcode values back with their page numbers.
New Capabilities: Generation
ML Kit does not generate barcodes - it only reads them. If your ported application needs to produce labels, tickets, or QR codes, IronBarcode covers that with the same package.
Code 128 for shipping labels:
using IronBarCode;
BarcodeWriter.CreateBarcode("SHIP-2024-98341", BarcodeEncoding.Code128)
.ResizeTo(400, 120)
.SaveAsPng("shipping-label.png");Imports IronBarCode
BarcodeWriter.CreateBarcode("SHIP-2024-98341", BarcodeEncoding.Code128) _
.ResizeTo(400, 120) _
.SaveAsPng("shipping-label.png")QR code generation:
using IronBarCode;
QRCodeWriter.CreateQrCode("https://example.com/track/98341", 500)
.SaveAsPng("tracking-qr.png");Imports IronBarCode
QRCodeWriter.CreateQrCode("https://example.com/track/98341", 500) _
.SaveAsPng("tracking-qr.png")QR code with logo and color:
using IronBarCode;
QRCodeWriter.CreateQrCode("https://example.com/product/4821", 500)
.AddBrandLogo("company-logo.png")
.ChangeBarCodeColor(System.Drawing.Color.DarkBlue)
.SaveAsPng("product-qr.png");Imports IronBarCode
QRCodeWriter.CreateQrCode("https://example.com/product/4821", 500) _
.AddBrandLogo("company-logo.png") _
.ChangeBarCodeColor(System.Drawing.Color.DarkBlue) _
.SaveAsPng("product-qr.png")Return barcode as byte array for an HTTP response:
using IronBarCode;
// In an ASP.NET Core controller action
byte[] barcodeBytes = BarcodeWriter.CreateBarcode("ORDER-7734", BarcodeEncoding.QRCode)
.ToPngBinaryData();
return File(barcodeBytes, "image/png");Imports IronBarCode
' In an ASP.NET Core controller action
Dim barcodeBytes As Byte() = BarcodeWriter.CreateBarcode("ORDER-7734", BarcodeEncoding.QRCode).ToPngBinaryData()
Return File(barcodeBytes, "image/png")None of these patterns have ML Kit equivalents. They are new capabilities available because you are working in a full .NET barcode library rather than a mobile-only scanner.
Server-Side Batch Processing
ML Kit processes one image per call, requires Android/iOS runtime, and has no concept of server-side execution. IronBarcode processes files in a loop, runs in ASP.NET Core, and scales normally:
using IronBarCode;
// Process a folder of scanned document images
var imageFiles = Directory.GetFiles("/data/scans", "*.jpg");
var allResults = new List<(string File, string Value, BarcodeEncoding Format)>();
foreach (var file in imageFiles)
{
var options = new BarcodeReaderOptions
{
Speed = ReadingSpeed.Faster,
ExpectMultipleBarcodes = false
};
var results = BarcodeReader.Read(file, options);
foreach (var barcode in results)
{
allResults.Add((file, barcode.Value, barcode.Format));
}
}
// Write results to CSV, database, etc.
foreach (var (file, value, format) in allResults)
{
Console.WriteLine($"{file}: [{format}] {value}");
}Imports IronBarCode
Imports System.IO
' Process a folder of scanned document images
Dim imageFiles = Directory.GetFiles("/data/scans", "*.jpg")
Dim allResults = New List(Of (File As String, Value As String, Format As BarcodeEncoding))()
For Each file In imageFiles
Dim options = New BarcodeReaderOptions With {
.Speed = ReadingSpeed.Faster,
.ExpectMultipleBarcodes = False
}
Dim results = BarcodeReader.Read(file, options)
For Each barcode In results
allResults.Add((file, barcode.Value, barcode.Format))
Next
Next
' Write results to CSV, database, etc.
For Each result In allResults
Console.WriteLine($"{result.File}: [{result.Format}] {result.Value}")
NextThis pattern - reading a folder of images, extracting barcodes, aggregating results - is not possible with ML Kit. It is a standard IronBarcode workflow.
Feature Comparison
| Feature | Google ML Kit | IronBarcode |
|---|---|---|
| .NET NuGet package | None | BarCode |
| C# / .NET API | None | Yes |
| Barcode reading | Yes (Android/iOS) | Yes (all platforms) |
| Barcode generation | No | Yes |
| QR code generation | No | Yes |
| QR logo embedding | No | Yes |
| PDF input | No | Yes |
| Multi-page document support | No | Yes |
| Camera/frame input | Yes | Via image file |
| Server-side deployment | No | Yes |
| ASP.NET Core | No | Yes |
| Azure Functions | No | Yes |
| Docker / Linux | No | Yes |
| Google Play Services required | Unbundled variant only | No |
| Firebase dependency | No (standalone since June 2020) | No |
| Synchronous .NET API | No | Yes |
| Dependency injection friendly | No | Yes (static API) |
ExpectMultipleBarcodes option | Via result list | BarcodeReaderOptions |
| Format specification | setBarcodeFormats() | ExpectBarcodeTypes |
| Speed/accuracy tradeoff | Fixed (model-based) | ReadingSpeed enum |
| Pricing | Free (on-device, mobile only) | From $999 (Lite) perpetual |
| Platforms | Android, iOS | Windows, Linux, macOS, Docker, Azure, AWS |
Migration Checklist
If you are porting an Android codebase or replacing an unofficial Xamarin ML Kit binding, search your project for these patterns and apply the translations above:
com.google.mlkit:barcode-scanningin Gradle files → remove, addBarCodeNuGetBarcodeScannerOptions.Builder()→new BarcodeReaderOptions { }BarcodeScanning.getClient(options)→ remove (no scanner instance in IronBarcode)InputImage.fromFilePath(context, uri)→ file path string argumentInputImage.fromBitmap(bitmap, rotation)→BarcodeReader.Read(stream)or byte array overloadscanner.process(inputImage)→BarcodeReader.Read(path, options).addOnSuccessListener { barcodes -> }→ iterate return value ofRead().addOnFailureListener { e -> }→ try/catch aroundRead()barcode.rawValue→barcode.Valuebarcode.format→barcode.FormatBarcode.FORMAT_QR_CODE→BarcodeEncoding.QRCodeBarcode.FORMAT_CODE_128→BarcodeEncoding.Code128Barcode.FORMAT_ALL_FORMATS→ omitExpectBarcodeTypesusing Google.MLKit.BarcodeScanning;(Xamarin binding) →using IronBarCode;IronBarCode.License.LicenseKeyshould be set inMauiProgram.cs,Program.cs, orStartup.cs
The structural change from callback-based to synchronous code is the main work. The format constants and result field names are direct mappings. PDF and generation support are purely additive - they require no migration, only new code.

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.