How to Validate QR Code Checksums and Apply Fault Tolerance in C#
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 ChecksumsRead a QR code and check whether decoding succeeded: a non-empty result means the Reed-Solomon checksum passed.
-
1Install IronQR with NuGet Package Manager
-
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# -
3Deploy to test on your live environment
Start using IronQR in your project today with a free trial
Minimal Workflow (5 steps)
- Download the IronQR C# library for QR code checksum validation
- Load an image with
QrImageInput - Call
QrReader.Readto decode the image and run Reed-Solomon validation automatically - Check the result collection to confirm decoding succeeded, as an empty collection means failure
- Validate the decoded value against application requirements before passing it downstream
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.

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}");
}
Output
The console shows the decoded value https://ironsoftware.com/, confirming that Reed-Solomon decoding succeeded and the payload was recovered intact.

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)

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

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.

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

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
- Error Correction Levels: write-time resilience and correction level configuration.
- Reading QR Codes How-To: input format options and read patterns.
- QrResult API Reference: complete property surface.
- Advanced Scan Examples: scan mode configurations.
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 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.