Categories
Geeky/Programming

VS2005 C++ Unit Tests – System.AccessViolationException: Attempted to read or write protected memory.

System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt..

If you have VS2005 C++ Unit Tests, written in managed C++ as they should be, and you are calling native code from them, and you see that error when running your unit tests – I have found it to mean that you are using insecure versions of methods (strcpy, etc). If you change the method calls to the secure versions, you should see your tests pass!

By Steve Novoselac

Director of Digital Technology @TrekBikes, Father, Musician, Cyclist, Homebrewer

3 replies on “VS2005 C++ Unit Tests – System.AccessViolationException: Attempted to read or write protected memory.”

What if you are calling a .dll and don’t have te source code of it? In that case I won’t be able to change the problematic functions (almost all of the dll) to the secure version. Any tip on this?

Like

hmm, not sure what you can do in that case then. if it is a 3rd party dll, I suggest contacting the creator and bugging them to change it. If it is an internal created dll, then maybe try finding the source, or creating a new dll yourself with the same functionality if it isn’t too huge or complicated.

Like

It’s an internal created dll, but from another department. I’ll try to get the original code or at least an example of how are they using that old dll with their new code. Thanks for the help.

Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.