IRONSOFTWAREHOME

How to Validate QR Code Checksums and Apply Fault Tolerance in C#

Curtis Chau
Curtis Chau
Updated: July 21, 2026

QR code pipelines that process real-world inputs, including printed labels, camera captures, or scanned documents, will encounter symbols that are too damaged to decode and results that pass the checksum but fail business validation.

Reed-Solomon error correction automatically addresses physical damage during decoding. If a symbol cannot be recovered, the result collection is empty rather than partial. Application-level validation is separate and involves checking that the decoded value is non-empty, matches the expected format, or contains a valid URI before further processing.

This how-to explains how to validate QR code checksums and apply fault tolerance checks with the IronQR library.

Quickstart: Validate QR Code Checksums

Read a QR code and check whether decoding succeeded: a non-empty result means the Reed-Solomon checksum passed.

  1. 1Install IronQR with NuGet Package Manager

    PM > Install-Package IronQR

  2. 2Copy and run this code snippet.

    using IronQr;
    using IronSoftware.Drawing;
    
    var reader = new QrReader();
    IEnumerable<QrResult> results = reader.Read(new QrImageInput(AnyBitmap.FromFile("label.png")));
    
    if (!results.Any())
    {
        Console.WriteLine("No QR code detected or decoding failed.");
        return;
    }
    
    Console.WriteLine(results.First().Value);
    C#
  3. 3Deploy to test on your live environment

    Start using IronQR in your project today with a free trial
    arrow pointer

Validating QR Code Checksums

QR codes use Reed-Solomon error correction to detect and repair damage to the encoded data. The correction level (Low at 7%, Medium at 15%, Quartile at 25%, or High at 30%) determines the percentage of codewords that can be lost and still be recovered.

On the reading side, checksum validation runs internally during decoding. The QrResult class does not expose a confidence property; if a result exists in the collection, the checksum passed. If decoding fails, the collection is empty.

Input

A QR code product label encoding https://ironsoftware.com/, generated with Medium error correction, representing a label that may have been handled or lightly scratched in transit.

QR code encoding https://ironsoftware.com used as input for checksum validation
using IronQr;
using IronSoftware.Drawing;

var reader = new QrReader();
IEnumerable<QrResult> results = reader.Read(new QrImageInput(AnyBitmap.FromFile("damaged-label.png")));

// Reed-Solomon decoding is pass/fail — presence in results means valid checksum
if (!results.Any())
{
    // Decoding failed entirely — damage exceeded the error correction capacity
    Console.WriteLine("QR code could not be decoded. Consider re-scanning or using a higher error correction level at generation time.");
    return;
}

foreach (QrResult result in results)
{
    // Decoded successfully — validate the content matches expected format
    if (string.IsNullOrWhiteSpace(result.Value))
    {
        Console.WriteLine("QR decoded but produced an empty value.");
        continue;
    }

    Console.WriteLine($"Valid QR: {result.Value}");
}
C#

Output

The console shows the decoded value https://ironsoftware.com/, confirming that Reed-Solomon decoding succeeded and the payload was recovered intact.

Terminal output showing Decoded QR Code: https://ironsoftware.com

For greater resilience to physical damage, generate QR codes with a higher error correction level. The High level recovers up to 30% data loss at the cost of a larger symbol.


Handling Format Awareness in QR Code Reading

IronQR supports three QR encoding formats: standard QR, Micro QR, and Rectangular Micro QR. The scanner automatically detects the format during reading. After scanning, the QrResult.QrType field provides the detected format as an enum value.

Scan mode determines the balance between speed and accuracy: Auto combines machine learning detection with a classic scan, OnlyDetectionModel uses only the ML model for faster processing, and OnlyBasicScan skips ML entirely for high-quality pre-processed images.

Input

A PNG product label (left) and a JPEG camera capture (right), demonstrating format-aware reading across two common input types.

product-label.png QR code used as input for format-aware reading

Product Label (PNG)

camera-capture.jpg JPEG QR code simulating a camera capture

Camera Capture (JPEG)

using IronQr;
using IronSoftware.Drawing;
using IronQr.Enum;

// Read from an image file with ML + classic scan (default)
var reader = new QrReader();
IEnumerable<QrResult> results = reader.Read(new QrImageInput(AnyBitmap.FromFile("product-label.png")));

foreach (QrResult result in results)
{
    // Inspect the detected QR format
    Console.WriteLine($"Format: {result.QrType}");   // QRCode, MicroQRCode, or RMQRCode
    Console.WriteLine($"Value:  {result.Value}");

    // Url is non-null only if Value is a valid URI
    if (result.Url != null)
    {
        Console.WriteLine($"URI:    {result.Url.AbsoluteUri}");
    }

    // Corner coordinates for positional context
    Console.WriteLine($"Corners: {result.Points.Length} points detected");
}

// Read from a bitmap with ML-only mode for faster throughput
var bitmap = AnyBitmap.FromFile("camera-capture.jpg");
var fastResults = reader.Read(new QrImageInput(bitmap, QrScanMode.OnlyDetectionModel));
C#

Output

The console shows the detected format, decoded value, resolved URI, and corner count for the product label, followed by the fast-scan result count for the camera capture.

Terminal output showing Format: QRCode, Value: https://ironsoftware.com/product, URI, and Corners: 4 points detected

The QrType field is helpful when the application requires a specific format. For example, a warehouse system that produces only standard QR codes can filter out unexpected Micro QR or Rectangular Micro QR detections, which may indicate noise or unrelated labels. Each format has distinct capacity characteristics: standard QR supports up to 7,089 numeric characters, Micro QR up to 35, and Rectangular Micro QR provides a rectangular form factor for limited label space.


Applying Null Checks to QR Code Results

QrReader.Read returns an empty collection if no QR codes are found; it never returns null. However, individual result properties still require validation. For example, Value may be empty, and Url returns null if the decoded string is not a valid URI.

A robust validation pattern checks three aspects: collection count, value integrity, and type or URI validity before passing data to another system.

Input

A blank white image with no QR code, representing a document page in a mixed batch where some pages carry no machine-readable label.

Blank white image with no QR code used as input for null checking demonstration
using IronQr;
using IronQr.Enum;
using IronSoftware.Drawing;
using System.Collections.Generic;
using System.Linq;

public static class QrValidator
{
    public static List<QrResult> GetValidResults(
        string imagePath,
        QrEncoding? expectedFormat = null)
    {
        var reader = new QrReader();
        IEnumerable<QrResult> results = reader.Read(new QrImageInput(AnyBitmap.FromFile(imagePath)));

        // Guard: no QR codes detected
        if (!results.Any())
            return new List<QrResult>();

        return results
            .Where(r => !string.IsNullOrWhiteSpace(r.Value))
            .Where(r => expectedFormat == null || r.QrType == expectedFormat)
            .ToList();
    }
}

// Usage — only accept standard QR codes with non-empty values
var validated = QrValidator.GetValidResults(
    "shipping-manifest.png",
    expectedFormat: QrEncoding.QRCode);

if (validated.Count == 0)
{
    Console.WriteLine("No valid QR codes found for processing.");
    return;
}

foreach (var qr in validated)
{
    // Safe for downstream: value is non-empty, format is verified
    SendToInventoryApi(qr.Value, qr.Url?.AbsoluteUri);
}
C#

Output

The console displays the validator's empty-result response: no QR codes were detected, so the collection is empty and no data proceeds to downstream processing.

Terminal output showing No valid QR codes found for processing.

The validator returns an empty list (never null), eliminating the need for null-checking at the call site. The optional expectedFormat parameter acts as a format gate, so the calling code receives only results that match the expected format type. The Url property uses the null-conditional operator to safely handle both URI and non-URI payloads.

For asynchronous workflows, apply the same validation patterns to ReadAsync: await the call and use identical checks on the resulting collection.


Further Reading

View licensing options when ready for production.

Click here to download the complete ChecksumFaultToleranceTest console app project.

Frequently Asked Questions

What is the importance of validating QR code checksums in C#?

Validating QR code checksums is crucial to ensure the integrity of the data encoded within QR codes. IronQR uses Reed-Solomon error correction to automatically address any physical damage during decoding, ensuring that the data retrieved is accurate and reliable.

How does Reed-Solomon error correction work in IronQR?

Reed-Solomon error correction in IronQR detects and repairs damage to encoded data up to a specific level. This correction level, which can be Low, Medium, Quartile, or High, determines the percentage of errors that can be recovered during decoding.

What should I do if a QR code cannot be decoded with IronQR?

If a QR code cannot be decoded using IronQR, it may be due to damage exceeding the error correction capacity. You can try re-scanning the code, generating the QR code again with a higher error correction level, or checking if the input image quality can be improved.

Can IronQR handle different QR encoding formats?

Yes, IronQR supports multiple QR encoding formats, including standard QR, Micro QR, and Rectangular Micro QR. The scanner automatically detects the format during reading, allowing for efficient and flexible QR code processing.

What happens if no QR codes are detected in an image using IronQR?

If no QR codes are detected using IronQR, the `QrReader.Read` method will return an empty collection. This indicates that decoding failed, and no actionable QR data was found.

How can I ensure that the QR code data is appropriate for my application requirements?

After decoding, you should validate the decoded value against specific application requirements, such as checking for expected formats or verifying that the content is non-empty and matches a valid URI.

Does IronQR provide format awareness during QR code reading?

Yes, IronQR provides format awareness by detecting the QR code format during reading. It returns the format as part of the `QrResult` object, allowing your application to handle specific formats appropriately.

What is the role of the `QrResult` class in IronQR?

The `QrResult` class in IronQR represents decoded results from QR code reading. It provides properties like the decoded value, detected QR type, and optionally, a URI if the value is a valid URL.

How does IronQR handle physical damage to QR codes?

IronQR uses Reed-Solomon error correction to automatically correct minor damages in QR codes during decoding, making it more resilient to physical damage and ensuring data integrity.

Can IronQR validate QR codes asynchronously?

Yes, IronQR supports asynchronous workflows. You can use `ReadAsync` to perform non-blocking QR code reading while applying similar validation patterns on the results.

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

Ready to Get Started?

Nuget Downloads 74,386Version:2026.9just released

Get your free 30-day Trial Key instantly.
No credit card or account creation required
C# NuGet Library for PDF
Install with NuGet

Version: 2026.9

PM > Install-Package IronQR
nuget.org/packages/IronQR/
  1. In Solution Explorer, right-click References, Manage NuGet Packages
  2. Select Browse and search "IronQR"
  3. Select the package and install
C# PDF DLL
Download DLL

Version: 2026.9

  1. Download and unzip IronQR to a location such as ~/Libs within your Solution directory
  2. In Visual Studio Solution Explorer, right click References. Select Browse, "IronQR.dll"

Licenses from $999

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