HOWTO: Load GlyphReaderEngine by Reflection


Our GlyphReader engine needs to be loaded by Reflection if being used in a Web App / Web Service / WCF service.

You need to prep for this by creating an OcrResources folder in your application /bin/ folder and placing the GlyphReader OCR resources in it. You will also need to go in to your project references and set the Atalasoft.dotImage.Ocr.GlyphReader.dll Copy Local property to false. Copy the Atalasoft.dotImage.Ocr.GlyphReader.dll in to the OcrResources folder as well. That will keep the web project from trying to load it when the application starts.

Use this simple method to handle the loading (make sure you set your paths)

/// <summary>

/// The GlyphReader Engine needs to be loaded by reflection in a web application...

/// </summary>

/// <returns></returns>

private OcrEngine CreateGlyphreaderEngine()
{
  
try
  
{
     
string ocrPath = Page.MapPath("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;
   }
}

Original Article:
Q10423 - HOWTO: Load GlyphReaderEngine by Reflection