Debugger error: Attempted to read or write protected memory

G

Guest

I have created an C++ application with Windows Forms, ADO and SQL server
2005. Now I need to change something and started debugging the code. Then
suddenly I receive an error.

"An unhandled exception of type 'System.AccessViolationException' occurred
in mscorlib.dll
Additional information: Attempted to read or write protected memory. This is
often an indication that other memory is corrupt."

The progran ends on a windows form designer generated line:
this->pictureBox1->Image = (cli::safe_cast<System::Drawing::Image^
(resources->GetObject(L"pictureBox1.Image")));

I ran a memory test and there is nothing wrong with the memory of the
computer. I even changed the memory chips with the same results. I also
defragmented the disks thinking of some help for possible swap area problems.
This didn't help.

The code compiles without errors and the funny thing is that when I ran the
compiled exe-file, it works without errors, only I can't debug the code.

The debugger produces a log as follows:
"
'C2.exe': Loaded 'D:\MEVET32\MEVET2005_1\MevetC3\C2\Debug\C2.exe', Symbols
loaded.
'C2.exe': Loaded 'C:\WINDOWS\system32\ntdll.dll', No symbols loaded.
'C2.exe': Loaded 'C:\WINDOWS\system32\mscoree.dll', No symbols loaded.
'C2.exe': Loaded 'C:\WINDOWS\system32\kernel32.dll', No symbols loaded.
'C2.exe': Loaded 'C:\WINDOWS\system32\advapi32.dll', No symbols loaded.
'C2.exe': Loaded 'C:\WINDOWS\system32\rpcrt4.dll', No symbols loaded.
'C2.exe': Loaded
'C:\WINDOWS\WinSxS\x86_Microsoft.VC80.DebugCRT_1fc8b3b9a1e18e3b_8.0.50727.42_x-ww_f75eb16c\msvcr80d.dll', Symbols loaded.
'C2.exe': Loaded 'C:\WINDOWS\system32\msvcrt.dll', No symbols loaded.
'C2.exe': Loaded
'C:\WINDOWS\WinSxS\x86_Microsoft.VC80.DebugCRT_1fc8b3b9a1e18e3b_8.0.50727.42_x-ww_f75eb16c\msvcm80d.dll', Symbols loaded.
'C2.exe': Loaded 'C:\WINDOWS\system32\ole32.dll', No symbols loaded.
'C2.exe': Loaded 'C:\WINDOWS\system32\gdi32.dll', No symbols loaded.
'C2.exe': Loaded 'C:\WINDOWS\system32\user32.dll', No symbols loaded.
'C2.exe': Loaded 'C:\WINDOWS\system32\shlwapi.dll', No symbols loaded.
'C2.exe': Loaded 'C:\WINDOWS\system32\shell32.dll', No symbols loaded.
'C2.exe': Loaded
'C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.2180_x-ww_a84f1ff9\comctl32.dll', No symbols loaded.
'C2.exe': Loaded 'C:\WINDOWS\system32\comctl32.dll', No symbols loaded.
'C2.exe': Loaded 'C:\WINDOWS\system32\wininet.dll', No symbols loaded.
'C2.exe': Loaded 'C:\WINDOWS\system32\crypt32.dll', No symbols loaded.
'C2.exe': Loaded 'C:\WINDOWS\system32\msasn1.dll', No symbols loaded.
'C2.exe': Loaded 'C:\WINDOWS\system32\oleaut32.dll', No symbols loaded.
'C2.exe': Loaded 'C:\WINDOWS\system32\psapi.dll', No symbols loaded.
'C2.exe': Loaded
'C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorwks.dll', No symbols
loaded.
'C2.exe': Loaded
'C:\WINDOWS\WinSxS\x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.42_x-ww_0de06acd\msvcr80.dll', Symbols loaded.
'C2.exe': Loaded
'C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Culture.dll', No symbols
loaded.
'C2.exe': Unloaded 'C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Culture.dll'
'C2.exe': Loaded
'C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\mscorlib\e5fcecdfe1e37b4da85a482f3ae3828a\mscorlib.ni.dll', No symbols loaded.
'C2.exe' (Managed): Loaded
'C:\WINDOWS\assembly\GAC_32\mscorlib\2.0.0.0__b77a5c561934e089\mscorlib.dll',
No symbols loaded.
'C2.exe': Loaded 'C:\WINDOWS\system32\uxtheme.dll', No symbols loaded.
'C2.exe': Loaded 'C:\WINDOWS\system32\msctf.dll', No symbols loaded.
'C2.exe': Loaded 'E:\OHJELMAT\ATI Technologies\HydraMDH.dll', Binary was not
built with debug information.
'C2.exe' (Managed): Loaded 'd:\MEVET32\MEVET2005_1\MevetC3\C2\Debug\C2.exe',
Symbols loaded.
'C2.exe': Loaded
'C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorjit.dll', No symbols
loaded.
'C2.exe': Loaded
'C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\diasymreader.dll', No symbols
loaded.
'C2.exe': Loaded 'C:\WINDOWS\system32\rsaenh.dll', No symbols loaded.
'C2.exe' (Managed): Loaded
'C:\WINDOWS\WinSxS\x86_Microsoft.VC80.DebugCRT_1fc8b3b9a1e18e3b_8.0.50727.42_x-ww_f75eb16c\msvcm80d.dll', Symbols loaded.
'C2.exe': Loaded
'C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\System\9ab675b1a240c545928e4db46e091273\System.ni.dll', No symbols loaded.
'C2.exe' (Managed): Loaded
'C:\WINDOWS\assembly\GAC_MSIL\System\2.0.0.0__b77a5c561934e089\System.dll',
No symbols loaded.
'C2.exe': Loaded
'C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\System.Drawing\891af85bc3dbcb4fb545fd59ede0c4c1\System.Drawing.ni.dll', No symbols loaded.
'C2.exe': Loaded
'C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\System.Windows.Forms\b92f931eb8bad2439d07738cb9a02ad7\System.Windows.Forms.ni.dll', No symbols loaded.
'C2.exe' (Managed): Loaded
'C:\WINDOWS\assembly\GAC_MSIL\System.Windows.Forms\2.0.0.0__b77a5c561934e089\System.Windows.Forms.dll', No symbols loaded.
'C2.exe' (Managed): Loaded
'C:\WINDOWS\assembly\GAC_MSIL\System.Drawing\2.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll', No symbols loaded.
'C2.exe': Loaded
'C:\WINDOWS\WinSxS\x86_Microsoft.Windows.GdiPlus_6595b64144ccf1df_1.0.2600.2180_x-ww_522f9f82\GdiPlus.dll', No symbols loaded.
First-chance exception at 0x009ba954 in C2.exe: 0xC0000005: Access violation
reading location 0x001f0000.
First-chance exception at 0x7c812a5b in C2.exe: Microsoft C++ exception:
[rethrow] at memory location 0x00000000..
A first chance exception of type 'System.AccessViolationException' occurred
in mscorlib.dll
An unhandled exception of type 'System.AccessViolationException' occurred in
mscorlib.dll

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

'C2.exe': Loaded
'C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\System.Configuration\b39f20c71193c542bbd774fd4df00b03\System.Configuration.ni.dll', No symbols loaded.
'C2.exe' (Managed): Loaded
'C:\WINDOWS\assembly\GAC_MSIL\System.Configuration\2.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll', No symbols loaded.
'C2.exe': Loaded
'C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\System.Xml\52bdb6df64cea543a5fbd60480b9abf4\System.Xml.ni.dll', No symbols loaded.
'C2.exe' (Managed): Loaded
'C:\WINDOWS\assembly\GAC_MSIL\System.Xml\2.0.0.0__b77a5c561934e089\System.Xml.dll', No symbols loaded.
The program '[776] C2.exe: Managed' has exited with code 0 (0x0).
The program '[776] C2.exe: Native' has exited with code 0 (0x0).
"

There were some hints that writing to protected memory could have something
to do with null values. This might not be true as the compiled exe-file works
fine without errors.

So the only problem is that I can't use the debugger.

Could you possibly have some solution to overcome this problem?
 
C

chris_doran

Ilkka said:
I have created an C++ application with Windows Forms, ADO and SQL server
2005. Now I need to change something and started debugging the code. Then
suddenly I receive an error.

"An unhandled exception of type 'System.AccessViolationException' occurred
in mscorlib.dll
Additional information: Attempted to read or write protected memory. This is
often an indication that other memory is corrupt."

The most likely explanation is that your program is overwriting
something, e.g. a buffer is too short for a string or a pointer value
is incorrect.

Finding these things is not easy. Examining your source code carefully
may find it. If it's a buffer overflow, you could change to the new _s
versions of memory/string functions. Another way is to increase the
size of all the arrays in your program and if that fixes it, change
them back one by one until you find which one is too small. If it's OK
with the previous version of your program, can you add the changes a
few at a time and see when it starts to go wrong? Otherwise you have to
do a lot of single stepping and examining memory.
I ran a memory test and there is nothing wrong with the memory of the
computer. I even changed the memory chips with the same results. I also
defragmented the disks thinking of some help for possible swap area problems.
This didn't help.

It's unlikely to be a hardware fault, as this would show on other
programs too.
The code compiles without errors and the funny thing is that when I ran the
compiled exe-file, it works without errors, only I can't debug the code.

It is not unusual for problems like this to be masked or unmasked by
use of the debugger, as this itself uses memory and can cause the stack
or heap to be used in different ways to a non-debugged program. Maybe
your program is writing to memory used by the debugger but which is
unused when run without it.

Chris
 
G

Guest

Thank you Chris Doran for your answer!
I didn't get an exact answer but your reply made me to try different things
for the code. I excluded one by one items in the code but finally it allways
collapsed on the same line. Without knowing what to do, I finally went and
deleted the picture in the PictureBox1. Then I inserted the image again, and
for some reason, the debugger started to function. The image is a wmf-file.
Not knowing what did take place - your guidance was helpul.
Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top