The type initializer for ' ' threw an exception on call to RecognizeImage/RecognizePdf

I have Aspose.OCR working well in my development environment, but when I publish to a staging server for further testing I am having issues.

The exception being triggered is: The type initializer for '​ ’ threw an exception.

This occurs on the call to RecognizeImage(filePath) when trying to OCR a JPG file.
This occurs on the call to RecognizePdf(filePath) when trying to OCR a PDF file.

The basic environment details are:

  • The solution is deployed as a website, using ASPX.
  • The target .NET Framework is 4.8.
  • The development environment is Visual Studio 2022
  • The staging server is hosted by Azure using Windows with IIS.

There is obviously some difference between my development environment and the staging environment. It could be the way the servers, application pools or websites are setup. It is probably an environmental issue, rather than a problem with the Aspose.OCR library itself.

To help me isolate the likely cause, can you advise:

  • What type of Object is being initialized at the time of the call?
  • What other libraries are being used?
  • Are there any IIS/Application Pool settings that should be checked?
  • Are there any web.config settings that should be applied?
  • Are there any permission settings that need to be checked?

Thanks in advance for your assistance!

Jonathan

After further investigation, the inner exception was determined to be:
System.DllNotFoundException: Unable to load DLL ‘onnxruntime’: The specified module could not be found. (Exception from HRESULT: 0x8007007E)

There is only one version of onnxruntime.dll on the staging server. This is in the bin folder under the web application.
The development server has the same version (19-Mar-2022 and 7,715KB) of onnxruntime.dll in the corresponding bin folder. However, it also has various other copies of onnxruntime.dll, including versions in:
“C:\Windows\SysWOW64\onnxruntime.dll”
“C:\Windows\System32\onnxruntime.dll”
These versions are both 7-Dec-2019 3KB.
Is there a setting required to make sure the system finds the correct version of the DLL?
Or should a version be put where the system can find it?

@jburnett

An investigation ticket as OCRNET-502 has been logged in our issue management system to further investigate this case. We need to further look into the details of such scenario. We will surely check the issue in details and let you know as soon as the ticket is resolved. Please be patient and spare us some time.

We are sorry for the inconvenience.

No need to investigate the issue any further.

Installing Microsoft Visual C++ Redistributable on the server seems to have resolved the problem.

@jburnett

It is nice to hear that your issue has been resolved. We have updated and closed the ticket now.