Fix: Leadtools.Forms.Ocr.OcrException. Image file create error.

If the Leadtools OCR engine is not started with the correct parameters, the exception "Image file create error" will be thrown. To fix this problem, make sure you start the OCR engine by executing the function Startup with parameter startupParameters set to the installation folder of Leadtools, like:

 

IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Plus, useThunkServer: false);
ocrEngine.Startup(null, null, "C:\Program Files (x86)\LeadTools\OCR Engine");

Leadtools error message “Operation failed” on Leadtools.Barcode.BarcodeException.CheckErrorCode

If you get the leadtools error message “Operation failed” in function Leadtools.Barcode.BarcodeException.CheckErrorCode, you should check if the following files are in the same folder as the assemlby that uses the leadtools assemblies:

Leadtools .NET assemblies:
Leadtools.Barcode.dll
Leadtools.Codecs.dll
Leadtools.dll
Leadtools.Forms.dll
Leadtools.Forms.Ocr.dll
Leadtools.Forms.Ocr.Plus.dll
Leadtools.ImageProcessing.Core.dll
Leadtools.ImageProcessing.Utilities.dll

Leadtools not .NET assemblies:
Ltbar4u.dll
Ltbar6ru.dll
Ltbar6wu.dll
Ltbar7ru.dll
Ltbar7wu.dll
Ltbar8ru.dll
Ltbar8wu.dll

Leadtools engine initialization error, or there is no appropriate license

If you get the error:

Leadtools.Forms.Ocr.OcrException : Engine initialization error, or there is no appropriate license.
at Leadtools.Forms.Ocr.Plus.OcrEngine.StartupEngine(String startupParameters)
at Leadtools.Forms.Ocr.Plus.OcrEngine.Startup(RasterCodecs rasterCodecs, String workDirectory, String startupParameters)

make sure the ocr engine is started with the correct path to the installation of the Leadtools.

 // Start OCR-engine var ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Plus, false);
            if (!ocrEngine.IsStarted)
            {
                ocrEngine.Startup(null, null, @“C:\InstallationFolderLeadTools”);
            }

 

The LeadTools OCR Engine should be installed in  C:\InstallationFolderLeadTools.

 

Adding LeadTools installation folder to the PATH variable

The error can some times be caused by the folder C:\InstallationFolderLeadTools not being in the PATH variable.

Add the [C:\InstallationFolderLeadTools] to the PATH variable.

Control Panel > System > Advanced System Settings

 

image

 

 

enable32BitAppOnWin64

This error can also be caused by an IIS or IIS express application pool not running in 32-bit application mode.

 

IIS

Change IIS Application Pool setting [Enable 32-bit Applications] to [True]

image

 

IIS Express

Add enable32BitAppOnWin64="true" in [C:\Users\User1\Documents\IISExpress\config\applicationhost.config].

<applicationPools>

            <add name="Clr4IntegratedAppPool" managedRuntimeVersion="v4.0" managedPipelineMode="Integrated" CLRConfigFile="%IIS_USER_HOME%\config\aspnet.config" autoStart="true" enable32BitAppOnWin64="true">

                <processModel loadUserProfile="true" />

            </add>

            <add name="Clr4ClassicAppPool" managedRuntimeVersion="v4.0" managedPipelineMode="Classic" CLRConfigFile="%IIS_USER_HOME%\config\aspnet.config" autoStart="true" enable32BitAppOnWin64="true"/>

            <add name="Clr2IntegratedAppPool" managedRuntimeVersion="v2.0" managedPipelineMode="Integrated" CLRConfigFile="%IIS_USER_HOME%\config\aspnet.config" autoStart="true" enable32BitAppOnWin64="true"/>

            <add name="Clr2ClassicAppPool" managedRuntimeVersion="v2.0" managedPipelineMode="Classic" CLRConfigFile="%IIS_USER_HOME%\config\aspnet.config" autoStart="true" enable32BitAppOnWin64="true"/>

            <add name="UnmanagedClassicAppPool" managedRuntimeVersion="" managedPipelineMode="Classic" autoStart="true" enable32BitAppOnWin64="true"/>

            <applicationPoolDefaults managedRuntimeLoader="v4.0">

                <processModel />

            </applicationPoolDefaults>

        </applicationPools>

Leadtools assembly load error, when building on a x64 platform

When you use leadtools in an assemlby and reference this assemlby by another assembly (e.g. a dll uses the Leadtools.Forms.Ocr and an executable references that dll), make sure that both assemlbies reference the Leadtools assembly, if not referenced assemlby load errors can occur.

When building these assemblies on an x64 platform and you are using the x86 leadtools assemblies, make sure you’re assemblies are build targeting the x86 platform, else assembly load errors can occur. 

image

Erros
Could not load file or assembly ‘Leadtools, Version=16.0.0.0, Culture=neutral, PublicKeyToken=9cf889f53ea9b907’ or one of its dependencies. An attempt was made to load a program with an incorrect format.
or
Could not load file or assembly ‘Leadtools.Barcode, Version=16.0.0.0, Culture=neutral, PublicKeyToken=9cf889f53ea9b907’
or
Could not load file or assembly ‘Leadtools.Codecs, Version=16.0.0.0, Culture=neutral, PublicKeyToken=9cf889f53ea9b907’
or
Could not load file or assembly ‘Leadtools.Forms, Version=16.0.0.0, Culture=neutral, PublicKeyToken=9cf889f53ea9b907’
or
Could not load file or assembly ‘Leadtools.Forms.Ocr, Version=16.0.0.0, Culture=neutral, PublicKeyToken=9cf889f53ea9b907’
or
Could not load file or assembly ‘Leadtools.Forms.Ocr.Plus, Version=16.0.0.0, Culture=neutral, PublicKeyToken=9cf889f53ea9b907’
etc.