Ok I have a project that runs fine from the IDE, the problem is if I install the app or run it from the bin\release folder then I get this error on one of my method calls. I have tried this on a test machine and on my development machine and the results are the same. I have spent hours trying to figure this one out....... The crazy thing is, the method shows up in the stack trace but there is not code at all executed in that method.

Wierd error : Attempted to read or write protected memory. This is often an indication that other memory is corrupt
jturpin
unfortunatelly your solution didn't help me with my problem, but it lead me to my own solution.
I told a colleague what you posted and he suggested, that those problems might be caused by bad compiler optimizations!
So I searched Visual Studio and found out that you can turn off compiler optimizations in "Properties/Compile/Advancec Compile Options" of the program.
Now my program seems to run fine, thanks! :)
Jamie Thomson
It runs fine when pressing the "Start Debugging"-Button in Visual Studio 2005, but this error occurs, when I run it from command line.
Besides VS 2005 Retail (no Beta!) the .NET framework 2.0 is installed, and the system is up to date (all updates from update.microsoft.com).
In my programm I've got two Event-Handler running side by side in their own threads. One Event-Handler gets active when there is data on the serial port (using System.IO.Ports) and the other is a SNMP-Trap-Handler which I've rewritten in VB.NET from a C#-example. This SNMP-Trap-Handler uses a .NET-interoperability-class which is needed to use the unmanaged code that the wsnmp32.dll from windows provides!
The SNMP-Event-handler, which I have rewritten in VB.NET, alone does run perfect, just like when the combinated programm is startet within Visual Studio, as I said before.
It seems to me, that the programm always aborts, when the SNMP-Handler gets active. If I just cause some serial data events, the programm runs just fine, even when started from command-line.
So I would expect the error within SNMP-Trap-Handler code, if asked!
But why does the programm run fine from within Visual Studio I have no idea!!!
Here is a link to that guy who developed the interoperability class und also the C#-snmp-trap-handler: http://dotnet.sys-con.com/read/38936.htm
Perhaps just one small update:
I have tested the programm with the original C# snmp-handler just to see if I made a mistake when rewriting it in VB.NET, but the problem is the same here.
I compiled the original trap-handler.cs file to a dll. A added this dll as a refernce to my other programm which handles the serial events and runs the main.
When I debug this in Visual Studio the programm runs fine again, just like it is supposed to. But when I start it from command line, I have the same problem:
Unhandled Exception: System.AccessViolationException: Attempted to read or write
protected memory. This is often an indication that other memory is corrupt.
I have no doubt what's going wrong!
What's the difference between running from command line and starting it from within Visual Studio
Sreekk
Swal
I was having the same problem when trying to instantiate a FoxPro .dll in my VS2005.net web application on the production server. My problem was in the COM .dll itself using a variable GETENV("TEMP").
The problem is that the web app was running as a user via the IIS Application Pooling and the GETENV("TEMP") variable was pointing to an environment variable that didn't exist (bad path)
My advice to you is to search your COM .dll with a fine-toothed comb and look at variables/paths that dont jive from client side testing to production server testing.
Good Luck!
mnoon
am using VS2005 and i can't seem to follow this navigations..or are u missing something
Battlekiller
I'm seeing this exception when calling an extern method on a COM DLL.
It's still early-days for my debugging, but it's quite frustrating. This worked fine with VS 2003, and I'm only seeing it now I try to upgrade.
Fingers crossed!
et381
This shouldn't happen in managed code. It's even odder that the error only happens when not debugging. Can you give the code for the method that causes the problem
Michael
magicalclick
ok, just an update on what I found. I had the following in a method
x=(variableA+variableB+ anothermathfunction(variableC,variableD));
what I changed that fixed my problem:
y= anothermathfunction(variableC,variableD);
x=(variableA+variableB+ y);
Now I cant explain this but after HOURS of trial and error this fixed my problem.
Good Luck......
paso
Paule_XE
Odd. Is your application multi-threaded What does anothermathfunction do
jwaddell
I had the exact same message when running my company's application, written in VS2003, on a new machine with only VS2005 installed. When I installed the .NET v1.1 runtime, the problem went away. I also saw it on another application, in that case I had to actually provide a config file for the EXE to make it run inside the v1.1 runtime, but again that fixed it.
Steve.
Robert Polding
Please note that I know very little about the inner working of software, and I'm sure it shows!
Best of luck,
RC
Jamie Thomson
You should set you Debugger in VS2005:
Tools->Options
Debugging->General
uncheck option "Suppress JIT optimization on module load"
shangan