Attempted to read or write protected memory. This is often an indication that other memory is corrupt
I have just faced this issue in VS 2013 .NET 4.5 with a MapInfo DLL. Turns out, the problem was that I changed the Platform for Build from x86 to Any CPU and that was enough to trigger this error. Changing it back to x86 did the trick. Might help someone.
I also faced this issue with Visual Studio(VS) 2010. More interestingly, I had several projects in my solution (Console application, WPF application, Windows Forms application) but it was failing only when, I was setting the "Console Application" type of project as start up project of the solution(Even for those which had literally no code or any additional assemblies referred apart from the default ones which come with project template itself).
Following change finally helped me nail down the issue: Go to project properties of the console application project (Alternatively, select project file in solution explorer and press Alt + Enter key combination) -> Go to Debug
tab -> Scroll to Enable Debuggers
section in right pane -> Check the Enable unmanaged code debugging
check box as shown in the snapshot below -> Click Floppy button in the toolbar to save project properties. Root cause of why it happened is still not known to me. Only thing I observed was that there were lot of windows updates which had got installed on my machine the previous night which mostly constituted of office updates and OS updates (More than a dozen KB articles).
Update: VS 2017 onward the setting name has changed as shown in the screenshot below:
Finally tracked this down with the help of WinDBG and SOS. Access violation was being thrown by some unknown DLL. Turns out a piece of software called "Nvidia Network Manager" was causing the problems. I'd read countless times how this issue can be caused by firewalls or antivirus, neither of which I am using so I dismissed this idea. Also, I was under the assumption that it was not environmental because it occurs on more than 1 server using different hardware. Turns out all the machines I tested this on were running "NVidia Network Manager". I believe it installs with the rest of the motherboard drivers.
Hopefully this helps someone as this issue was plaguing my application for a very long time.