I do set the license on page load.
How do I upload the project?
I do set the license on page load.
How do I upload the project?
I have removed all the dlls and my zip shows that it is 26MB but when I attempt to upload I get a message that says:
Sorry, that file is too big (maximum size is 48.8 MB). Why not upload your large file to a cloud sharing service, then paste the link?
Please advise.
Looks like it is a private link. Could you please share public link because we are not able to access it.
I made it public. You should be able to access it now
Thanks for providing the requested information and your patience with us. We have tested with your application and looks like the culprit is below line of code:
input.Add("\Files\OCRTest.pdf", startPage:=1, pagesCount:=1)
The input document has only one page and index starts from 0. So it should be added like below:
input.Add("\Files\OCRTest.pdf", startPage:=0, pagesCount:=1)
Just by modifying like above, we were able to generate correct output.
OCRTestOCR_0.pdf (417.7 KB)
I started a new project and changed the StartPage to 0. When the app is run I get the error:
System.IO.FileNotFoundException: ‘Could not load file or assembly ‘Microsoft.ML.OnnxRuntime, Version=0.0.0.0, Culture=neutral, PublicKeyToken=f27f157f0a5b7bb6’ or one of its dependencies. The system cannot find the file specified.’
So I went to NuGet and added Microsoft.ML.OnnxRuntime version 1.20.1. Now when I run it it errors in code in NativeMethods.shared.cs. The error is:
System.NullReferenceException
HResult=0x80004003
Message=Object reference not set to an instance of an object.
Source=Microsoft.ML.OnnxRuntime
StackTrace:
at Microsoft.ML.OnnxRuntime.NativeMethods…cctor() in D:\a_work\1\s\csharp\src\Microsoft.ML.OnnxRuntime\NativeMethods.shared.cs:line 368
This module got loaded with the OnnxRuntime. Please advice.
Please make sure that you start a project with .NET Framework >=4.6.2. Also, please install Aspose.OCR for .NET from NuGet Package Manager because this way it will install all dependencies with correct versions. As shared earlier, we performed all these steps and did not notice any issues in our environment.
Ok. I changed the framework to 4.6.2 but it still errors. I even started a new project but get the same error. In both scenarios I added Aspose.OCR using NuGet manager. The error occurs on the code line:
Dim resultsNoStamp As List(Of RecognitionResult) = ocr.Recognize(input, settings)
Here are the details from the error:
System.NullReferenceException
** HResult=0x80004003**
** Message=Object reference not set to an instance of an object.**
** Source=Microsoft.ML.OnnxRuntime**
** StackTrace:**
** at Microsoft.ML.OnnxRuntime.NativeMethods…cctor() in D:\a_work\1\s\csharp\src\Microsoft.ML.OnnxRuntime\NativeMethods.shared.cs:line 368**
Please download a sample project at given link and test using it. You can change the path to .lic and other input/output files according to your environment and let us know if you face issues with it.
I downloaded the sample project and it error on the same line of code. The problem is in the NativeMethods.shared.cs code at line 368.
The line is:
OrtCreateEnv = (DOrtCreateEnv)Marshal.GetDelegateForFunctionPointer(api_.CreateEnv, typeof(DOrtCreateEnv));
It is strange because we tested using same application in our environment and we did not face any issues. Are you testing it in Windows? Also, is it x86 architecture only at your end? Can you please make sure that the project is configured to use x64? Please share some screenshots of the issue and full environment details for our reference so that we can proceed with the investigation.
Sorry for the delay in responding. I have been out of the office.
We have the setting as Any CPU. When I try it with x64 I get the following error:
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.BadImageFormatException: Could not load file or assembly ‘OCR1’ or one of its dependencies. An attempt was made to load a program with an incorrect format.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Assembly Load Trace: The following information can be helpful to determine why the assembly ‘OCR1’ could not be loaded.
LOG: This bind starts in default load context.
LOG: Using application configuration file: S:\Visual Studio 2013\Projects - Beta\OCR1\web.config
LOG: Using host configuration file: C:\Users\Russ\Documents\IISExpress\config\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Users/Russ/AppData/Local/Temp/Temporary ASP.NET Files/vs/933423e0/35293208/OCR1.DLL.
LOG: Attempting download of new URL file:///C:/Users/Russ/AppData/Local/Temp/Temporary ASP.NET Files/vs/933423e0/35293208/OCR1/OCR1.DLL.
LOG: Attempting download of new URL file:///S:/Visual Studio 2013/Projects - Beta/OCR1/bin/OCR1.DLL.
ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.`
Stack Trace:
`[BadImageFormatException: Could not load file or assembly ‘OCR1’ or one of its dependencies. An attempt was made to load a program with an incorrect format.]
System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0
System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +37
System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +159
System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) +80
System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +22
System.Reflection.Assembly.Load(String assemblyString) +29
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +38
[ConfigurationErrorsException: Could not load file or assembly ‘OCR1’ or one of its dependencies. An attempt was made to load a program with an incorrect format.]
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +726
System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +196
System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +45
System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +172
System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies() +91
System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +111
System.Web.Compilation.BuildManager.ExecutePreAppStart() +156
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +695
[HttpException (0x80004005): Could not load file or assembly ‘OCR1’ or one of its dependencies. An attempt was made to load a program with an incorrect format.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +660
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +89
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +189`
Have you tried using same application on another machine with different environment? Because we have used and shared same application with you and it was created from scratch. We are still unable to replicate these errors in our environment. The issue apparently looks related with System Configurations. Please share your complete environment details e.g. Windows OS Name and Version so that we can further try to investigate the issue and address it accordingly.
I thought maybe the issue was I have been running the code from the development environment (on my development PC). I published to our test server and I get the following message:
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
Parser Error Message: The CodeDom provider type “Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35” could not be located.
Source Error:
Line 49: <compilers> Line 50: <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701" /> Line 51: <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+" /> Line 52: </compilers> Line 53: </system.codedom>
Source File: C:\inetpub\wwwroot\ALJ\ocr\web.config Line: 51
The issue still seems related to missing DLLs and assembly references. It is very hard to replicate it in our environment. We will certainly assist you in resolving the issue if we could replicate it somehow at our end. If possible, please share such information that could help us in reproducing the error and then address it accordingly.
My Environment:
Microsoft Visual Studio Professional 2019
Version 16.11.33
Processor Intel(R) Core™ i7-9700 CPU @ 3.00GHz 3.00 GHz
Installed RAM 16.0 GB (15.8 GB usable)
|Device ID|170CCF1E-E948-4872-ACC7-A479154636B1|
System type 64-bit operating system, x64-based processor
Windows 11 Pro
Version 23H2
OS build 22631.5039
Experience Windows Feature Experience Pack 1000.22700.1074.0
Here is the file that causes the error on line 368. I had to change the extension to get it to upload, The extension should be .cs
NativeMethods.shared.docx (136.2 KB)
My Code:
Imports Aspose.OCR
Public Class WebForm1
Inherits System.Web.UI.Page
Protected Sub cmdOCR_Click(sender As Object, e As EventArgs) Handles cmdOCR.Click
Dim LicWords As New Aspose.OCR.License
LicWords.SetLicense("\\tlhfms\Aspose\Aspose.OCR.NET.lic")
Dim ocr As New AsposeOcr()
Dim settings As New RecognitionSettings()
settings.Language = Language.Eng
Dim input As New OcrInput(InputType.PDF)
input.Add("C:\Users\Russ\Documents\OCRInput.pdf", startPage:=0, pagesCount:=1)
Dim resultsNoStamp As List(Of RecognitionResult) = ocr.Recognize(input, settings)
AsposeOcr.SaveMultipageDocument("C:\Users\Russ\Documents\OCROutput.pdf", SaveFormat.Pdf, resultsNoStamp)
End Sub
End Class
The error occurs on the line:
Dim resultsNoStamp As List(Of RecognitionResult) = ocr.Recognize(input, settings)
Error Details:
System.NullReferenceException
HResult=0x80004003
Message=Object reference not set to an instance of an object.
Source=Microsoft.ML.OnnxRuntime
StackTrace:
at Microsoft.ML.OnnxRuntime.NativeMethods…cctor() in D:\a_work\1\s\csharp\src\Microsoft.ML.OnnxRuntime\NativeMethods.shared.cs:line 368
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): OCRNET-1017
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.