IronOCR Language Pack Not Found in .NET MAUI Android Projects
Summary
In .NET MAUI Android projects using IronOCR, attempting to use non-English languages (e.g., Chinese) results in the error below:
System.IO.FileNotFoundException: Language Pack Not Found: chi_sim.traineddata
This occurs even if the language pack file exists in the Assets/tessdata folder and is marked as an AndroidAsset.
Root Cause
When building .NET MAUI Android projects using Visual Studio Code or CLI, the Android build process may fail to properly resolve or include the language data files required by IronOCR. Consequently, IronOCR cannot locate the necessary *.traineddata files at runtime.
Resolution (Recommended)
Use Visual Studio 2022 (v17.10 or later) and open the project in the full Visual Studio IDE. This ensures that the dependencies are correctly included in the Android APK during the build process.
Once the project is build,
-
Move
OcrDatafolder frombinto the root of your project, for example:OcrData/chi_sim.traineddata. -
Modify your
.csprojfile to include the trained data as Android assets:<ItemGroup>
<AndroidAsset Include="OcrData\chi_sim.traineddata" />
<AndroidAsset Include="ocrData\chi_tra.traineddata"/>
</ItemGroup> -
Ensure font support: Add fonts to your MAUI project that support Chinese characters to avoid display issues in the app UI. You can include fonts like Noto Sans SC in your
Resources/Fontsdirectory and register them inMauiProgram.cs.using Microsoft.Extensions.Logging;
namespace MauiApp2
{
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
});
#if DEBUG
builder.Logging.AddDebug();
#endif
return builder.Build();
}
}
}
Correct Project Structure Example
ProjectRoot/
├── OcrData/
│ └── chi_sim.traineddata
├── Resources/
│ └── Fonts/
│ └── NotoSansSC-Regular.ttf
├── MyMauiApp.csproj
Additional Notes
-
Ensure that
IronOcr.Androidis properly installed and restored via NuGet. -
Enable logging for IronOCR to confirm the search paths for language files:
IronSoftware.Logger.LoggingMode = IronSoftware.Logger.LoggingModes.All;
IronSoftware.Logger.LogFilePath = "OcrMaui.log"; -
Using
.tessdatafolders underAssets/may fail silently on CLI or VS Code builds, which is why the manual relocation of.traineddatais sometimes necessary.