We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

OCR.AsposeOcr Issue

I tried the following sample snippets but got error “The type initializer for '​ ’ threw an exception. - The type initializer for ‘Microsoft.ML.OnnxRuntime.NativeMethods’ threw an exception.” at this line var res = api.RecognizePdf(dataDir + “BRZ0000001.pdf”, settings);

Can you tell me what I did wrong?

// C# Code
var api = new OCR.AsposeOcr();

var settings = new OCR.DocumentRecognitionSettings();
settings.StartPage = 0;
//settings.PagesNumber = 2;
//settings.LinesFiltration = true;
settings.DetectAreas = true;
settings.DetectAreasMode = OCR.DetectAreasMode.COMBINE;
settings.ThreadsCount = 1;

var res = api.RecognizePdf(dataDir + “BRZ0000001.pdf”, settings);

OCR.AsposeOcr.SaveMultipageDocument(dataDir + “test2.pdf”, OCR.SaveFormat.Pdf, res);

@vnguyen

The Aspose.OCR for .NET API has a dependency on OnnxRutime library. Please try to install the API using NuGet Package Manager and all the dependencies would get installed automatically. In case you still face any issues, please let us know.

I did try to install the Aspose.OCR for .NET API using NuGetPackage Manager but still got the same error. I do see the Microsoft.ML.OnnXRuntime in my project’s Reference.

@vnguyen

Would you please share the .NET Framework Version and Visual Studio version that you are using?

I have .NET Framework 4.8 and Visual Studio 2017.

@vnguyen

It seems strange because we tested using the same setting i.e. .NET Framework 4.8 and Visual Studio 2017 and we did not notice any issue. Please check the packages folder in the screenshot that shows the version numbers of the dependencies as well. Please try to create a fresh console application and install the API from NuGet and share that application with us if you still notice any issues in it.dep.png (5.9 KB)

It is working fine with console application but not for the ASP.NET Web Application. Why does it work for console app but not web app?

@vnguyen

We were able to reproduce the issue in our environment and have logged it as OCRNET-559 in our issue tracking system. We will further look into its details and let you know as soon as it is rectified. Please be patient and spare us some time.

We are sorry for the inconvenience.

Thank you!

Do you have any status for PDFNET-51359?

@vnguyen

We are afraid that the earlier logged ticket could not get resolved due to other pending issues in the queue. We will surely resolve and fix it on first come first serve basis and let you know as soon as it we have further updates in this regard.

We apologize for the inconvenience.

We would like to get all stamps for a pdf document. Hope the GetStamps method will be resolved soon.

@vnguyen

We will surely investigate the ticket and rectify the functionality of the method i.e. GetStamps. We will let you know once the ticket is resolved.

@vnguyen

Please try to create a project with Target x86, then install Aspose.OCR.

The problem with Onnxruntime is that it doesn’t work with AnyCPU. And when you install Aspose.OCR with the AnyCPU project, you have the wrong version of the ONNX runtime. Please try this solution. Hope it helps.