BACKGROUND
There are certain circumstances where our GlyphReaderEngine class will not load normally. In these cases, it requires loading via reflection instead.
Common circumstances:
- Code-behind or in a handler in a Web application (ASP.NET)
- As part of a WCF service
- When targeting .NET 8+
PREPARATION
You need to prep
for this by creating an OcrResources folder in your application /bin/ folder
Note that the /bin/ folder could vary depending on your targeting
- /bin
- /bin/Release
- /bin/Debug/net8.0-windows
- etc...
Once you've created that OcrResources folder, You will need to navigate to the OcrResources directory where the SDK has been installed - typically
C:\Program Files (x86)\Atalasoft\DotImage 11.5\bin\OCRResources
Go into that directory and Copy the entire GlyphReader directory into your /bin/OcrResources directory
You also need to copy the Atalasoft.dotImage.Ocr.GlyphReader.dll from the SDK install for your target and bitness into the /bin/OcrResources root folder
For instance if you're working with .NET 8.0 in DotImage 11.5 x64, this would be
C:\Program Files (x86)\Atalasoft\DotImage 11.5\bin\6.0\x64\Atalasoft.dotImage.Ocr.GlyphReader.dll
Now, You must also go into your application solution explorer in Visual Studio and set the Copy Local property of the Atalasoft.dotImage.Ocr.GlyphReader.dll reference to No
THE CODE TO LOAD
Use this simple
method to handle the loading (make sure you set your paths)
private static OcrEngine CreateGlyphreaderEngine()
{
try
{
string ocrPath = System.IO.Directory.GetCurrentDirectory() + "\\OcrResources\\";
GlyphReaderLoader loader = new GlyphReaderLoader(ocrPath);
string dllPath = ocrPath + "/Atalasoft.dotImage.Ocr.Glyphreader.dll";
Assembly asm = Assembly.LoadFile(dllPath);
Type obj = asm.GetType("Atalasoft.Ocr.GlyphReader.GlyphReaderEngine");
ConstructorInfo ci = obj.GetConstructor(new Type[0]);
OcrEngine engine = ci.Invoke(null) as OcrEngine;
return engine;
}
catch
{
return null;
}
}
CREATING AND USING THE ENGINE
Now that you have all of this in place, you can finally use the Engine...
OcrEngine engine = CreateGlyphreaderEngine();
engine.Initialize();
OcrPage sampePage = engine.Recognize( AtalaImageHere );
...
SAMPLE APPLICATION
GlyphReaderConsole_net8.zip - A .NET 8 example
Original Article
Q10423 - HOWTO: Load GlyphReaderEngine by Reflection
Last Update
2026-01-05 - TD