Attempted to read or write protected memory

Why does the “System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.” error message appear?

This message usually occurs if you try to access non-existing object or attempt to use Engine from different threads simultaneously.

Engine object is 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 Help, FAQ section "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 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.

Was this article helpful?

0 out of 0 found this helpful

Have more questions? Submit a request

Recently viewed