Error "System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt." appears during the processing
This message usually occurs if you try to access a non-existing object or attempt to use the Engine from different threads simultaneously, but don't use Inproc our Outproc loader.
If you work with COM "naked" interface:
Engine object is a singleton, so it must be initialized, used and deinitialized within one and the same STA thread strictly (default apartment in .Net is MTA). Otherwise, program behavior can be unpredictable. This fact is mentioned in FineReader Engine Developer's Guide FAQ under Using the Engine object.
To check how the Engine object is used in your application, you can log current thread ID and apartment state after every Engine method call: ID must be the same and Apartment state must be STA during all the process of Engine usage, from initialization to unloading.
Please make sure that this requirement is fulfilled for your application. If it is not, then you will need to modify your application structure, so the Engine is definitely used in one STA thread. You can, for example, implement all Engine methods within one separate thread and set this thread apartment state to STA before starting it from service main function.
If this does not suit you, please change to in-process or out-of-process COM loading methods. Please check FineReader Engine Developer's Guide article Guided Tour > Advanced Techniques > Programming Aspects > Different Ways to Load the Engine Object for full information.
If you work with the InprocLoader or OutprocLoader object
Please make sure that the version of the .NET Framework or .NET Core interop assembly referenced in your project matches the installed version of FineReader Engine and the settings of your project.
If necessary, remove the reference to the incorrect version of the interop assembly and replace it with the correct one. The interop assemblies for the installed version of FineReader Engine 12 can be found in the C:\ProgramData\ABBYY\SDK\12\FineReader Engine\Inc folder.
I was able to address this issue with by performing below step.
Thank you for sharing your solution! We updated the article accordingly.
Please sign in to leave a comment.