IRONSOFTWAREHOME
MIGRATION GUIDES

Migrating from Google ML Kit Barcode Scanning to IronBarcode

Curtis Chau
Curtis Chau
Updated: August 1, 2026

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:

dotnet add package BarCode

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";

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}")
    }
Text

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}");
}

The 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") }
Text

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);
}

Format 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 KotlinIronBarcode C#
Barcode.FORMAT_QR_CODEBarcodeEncoding.QRCode
Barcode.FORMAT_CODE_128BarcodeEncoding.Code128
Barcode.FORMAT_CODE_39BarcodeEncoding.Code39
Barcode.FORMAT_CODE_93BarcodeEncoding.Code93
Barcode.FORMAT_EAN_13BarcodeEncoding.EAN13
Barcode.FORMAT_EAN_8BarcodeEncoding.EAN8
Barcode.FORMAT_UPC_ABarcodeEncoding.UPCA
Barcode.FORMAT_UPC_EBarcodeEncoding.UPCE
Barcode.FORMAT_PDF417BarcodeEncoding.PDF417
Barcode.FORMAT_DATA_MATRIXBarcodeEncoding.DataMatrix
Barcode.FORMAT_AZTECBarcodeEncoding.Aztec
Barcode.FORMAT_ITFBarcodeEncoding.ITF
Barcode.FORMAT_CODABARBarcodeEncoding.Codabar
Barcode.FORMAT_ALL_FORMATSOmit 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);

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
Text
// IronBarcode C# — result fields
string value = barcode.Value;
BarcodeEncoding format = barcode.Format;
int page = barcode.PageNumber; // populated for PDF / multi-page input

barcode.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;
    });
}

No 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}");
}

No 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");

QR code generation:

using 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");

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");

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}");
}

This pattern - reading a folder of images, extracting barcodes, aggregating results - is not possible with ML Kit. It is a standard IronBarcode workflow.

Feature Comparison

FeatureGoogle ML KitIronBarcode
.NET NuGet packageNoneBarCode
C# / .NET APINoneYes
Barcode readingYes (Android/iOS)Yes (all platforms)
Barcode generationNoYes
QR code generationNoYes
QR logo embeddingNoYes
PDF inputNoYes
Multi-page document supportNoYes
Camera/frame inputYesVia image file
Server-side deploymentNoYes
ASP.NET CoreNoYes
Azure FunctionsNoYes
Docker / LinuxNoYes
Google Play Services requiredUnbundled variant onlyNo
Firebase dependencyNo (standalone since June 2020)No
Synchronous .NET APINoYes
Dependency injection friendlyNoYes (static API)
ExpectMultipleBarcodes optionVia result listBarcodeReaderOptions
Format specificationsetBarcodeFormats()ExpectBarcodeTypes
Speed/accuracy tradeoffFixed (model-based)ReadingSpeed enum
PricingFree (on-device, mobile only)From $999 (Lite) perpetual
PlatformsAndroid, iOSWindows, 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-scanning in Gradle files → remove, add BarCode NuGet
  • BarcodeScannerOptions.Builder()new BarcodeReaderOptions { }
  • BarcodeScanning.getClient(options) → remove (no scanner instance in IronBarcode)
  • InputImage.fromFilePath(context, uri) → file path string argument
  • InputImage.fromBitmap(bitmap, rotation)BarcodeReader.Read(stream) or byte array overload
  • scanner.process(inputImage)BarcodeReader.Read(path, options)
  • .addOnSuccessListener { barcodes -> } → iterate return value of Read()
  • .addOnFailureListener { e -> } → try/catch around Read()
  • barcode.rawValuebarcode.Value
  • barcode.formatbarcode.Format
  • Barcode.FORMAT_QR_CODEBarcodeEncoding.QRCode
  • Barcode.FORMAT_CODE_128BarcodeEncoding.Code128
  • Barcode.FORMAT_ALL_FORMATS → omit ExpectBarcodeTypes
  • using Google.MLKit.BarcodeScanning; (Xamarin binding) → using IronBarCode;
  • IronBarCode.License.LicenseKey should be set in MauiProgram.cs, Program.cs, or Startup.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
Technical Writer

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.

...
Read More

Related Articles

Key in blue circle

Get your free 30-day Trial Key instantly.

Your trial license will be sent to your email address

No limitations. 100% unlocked. No credit card.

bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
Book your free Live Demo
Booking Badge

Trusted by Millions of Engineers Worldwide

Iron Software's customer logos
Get Your No-Obligation Consult
Complete the form below or email sales@ironsoftware.com
Your details will always be kept confidential.
Trusted by Millions of Engineers Worldwide
Iron Software's customer logos
Get your free 30-day Trial Key instantly.
No credit card or account creation required