32-bit build crash
When building in release mode, ReadProcessMemory() or GCHandle.Alloc() cause an AccessViolationException
Debug build works fine. Only happens in release. Strange....
Perhaps those kernel calls need admin access? Try running the prod exe under admin privs.
Ah, so it's not release mode or privileges, but platform. I had my debug build set to 'Any CPU' (which defaulted to x64), and Release build set to 'x86'. When I set it to x64 / Any CPU it runs fines.
So it only works in 64-bit build. 32-bit is broken.
My best guess at this moment is there is a size mismatch somewhere. Something is trying to read/write a 64-bit address into a 32-bits, or vice versa. Probably the IntPtr or Marshal, maybe buffer size. Will look into more later.
Perhaps some of the P/invoke calls are only for x64 definitions and need separate wrappings per cpu build.