Sunday, March 13, 2011

"Attempted to read or write protected memory" when accessing 32 bit third party assembly

"Unexpected errors happen when executing 32 bit code that tries to call 64 bit code and viceversa".

Using third party assemblies compiled as 32 bit will throw an exception at runtime if you compiled your solution as "Any CPU" and then run it on a 64 bit machine. This option lets the application run as 32 bit or 64 bit depending on the target machine. The solution is to make sure you compile your application as 32 bit. Simple huh?