472,330 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,330 software developers and data experts.

Debugger error: Attempted to read or write protected memory

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_1fc 8b3b9a1e18e3b_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_1fc 8b3b9a1e18e3b_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\msc orwks.dll', No symbols
loaded.
'C2.exe': Loaded
'C:\WINDOWS\WinSxS\x86_Microsoft.VC80.CRT_1fc8b3b9 a1e18e3b_8.0.50727.42_x-ww_0de06acd\msvcr80.dll', Symbols loaded.
'C2.exe': Loaded
'C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Cul ture.dll', No symbols
loaded.
'C2.exe': Unloaded 'C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Cul ture.dll'
'C2.exe': Loaded
'C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\ms corlib\e5fcecdfe1e37b4da85a482f3ae3828a\mscorlib.n i.dll', No symbols loaded.
'C2.exe' (Managed): Loaded
'C:\WINDOWS\assembly\GAC_32\mscorlib\2.0.0.0__b77a 5c561934e089\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\msc orjit.dll', No symbols
loaded.
'C2.exe': Loaded
'C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\dia symreader.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_1fc 8b3b9a1e18e3b_8.0.50727.42_x-ww_f75eb16c\msvcm80d.dll', Symbols loaded.
'C2.exe': Loaded
'C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\Sy stem\9ab675b1a240c545928e4db46e091273\System.ni.dl l', No symbols loaded.
'C2.exe' (Managed): Loaded
'C:\WINDOWS\assembly\GAC_MSIL\System\2.0.0.0__b77a 5c561934e089\System.dll',
No symbols loaded.
'C2.exe': Loaded
'C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\Sy stem.Drawing\891af85bc3dbcb4fb545fd59ede0c4c1\Syst em.Drawing.ni.dll', No symbols loaded.
'C2.exe': Loaded
'C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\Sy stem.Windows.Forms\b92f931eb8bad2439d07738cb9a02ad 7\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.dl l', 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_6 595b64144ccf1df_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\Sy stem.Configuration\b39f20c71193c542bbd774fd4df00b0 3\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.dl l', No symbols loaded.
'C2.exe': Loaded
'C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\Sy stem.Xml\52bdb6df64cea543a5fbd60480b9abf4\System.X ml.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?

--
Ilkka P
Sep 26 '06 #1
2 21817

Ilkka wrote:
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

Sep 26 '06 #2
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!
--
Ilkka P
"ch*********@postmaster.co.uk" wrote:
>
Ilkka wrote:
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

Sep 26 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: hiralparikh | last post by:
Hi, I am using .NET 2.0 and trying to use a function from a native DLL file. Here is the syntax that I am using: definition: public static...
3
by: XJ | last post by:
Hi experts, i try to use vb.net 2005 call dll, then give me "Attempted to read or write protected memory.This is often an indication that other...
1
by: ianyian | last post by:
Hi experts, i try to use vb.net 2005 call C++ dll, then give me "Attempted to read or write protected memory.This is often an indication that...
1
by: Michael | last post by:
Hi Everyone, This is a first for me. I'm getting this error: Attempted to read or write protected memory. This is often an indication that other...
0
by: bardiyam | last post by:
hi to all, can any body help me to solve this error.... unhandled exception : attempted to read or write protected memory. this is often...
5
by: Jeff | last post by:
Okay, I'm still new to vb.net 2005 - throught this was a hardware problem, but now I don't know. (I'm having some problem with my newgroup...
1
by: Marc Bartsch | last post by:
Hi, My C# app throws the following exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an...
6
by: Scott Gravenhorst | last post by:
Windows XP SP3 My application is set to open a SaveFile dialog when an exit is requested. When I click the app's close button, the save dialog...
0
by: jay123 | last post by:
hi all, I m using a web service but i m geeting an error - ex {"An error (Unable to read data from the transport connection: Attempted to read...
0
by: tammygombez | last post by:
Hey everyone! I've been researching gaming laptops lately, and I must say, they can get pretty expensive. However, I've come across some great...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.