none
Wierd error : Attempted to read or write protected memory. This is often an indication that other memory is corrupt

    Question

  • 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.
    Friday, January 13, 2006 3:29 PM

Answers

  • You should set you Debugger in VS2005:

    Tools->Options

    Debugging->General

    uncheck option "Suppress JIT optimization on module load"

     

     

    Monday, January 23, 2006 11:12 AM

All replies

  •  Mike Martin wrote:
    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.

    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

    • Proposed as answer by justinclarke Thursday, January 14, 2010 2:29 PM
    Friday, January 13, 2006 4:05 PM
  • I get the exact same error on startup of MS Outlook w/ business contact manager.  In my quest to find out what was causing it, I stumbled upon your post.  No other apps running, sys is Dell XPS 2 laptop w/ MS office 2003.  The problem makes Outlook unusable.  I'm guessing the program or system is ordering the executing of a write command faster than the memory is released?

    Please note that I know very little about the inner working of software, and I'm sure it shows!

    Best of luck,

    RC
    Tuesday, January 17, 2006 2:08 AM
  • I've got the same problem with my own developed Programm!
    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???
    Thursday, January 19, 2006 8:40 AM
  • 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......

    Thursday, January 19, 2006 1:30 PM
  •  Mike Martin wrote:

    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......

    Odd. Is your application multi-threaded? What does anothermathfunction do?

    Thursday, January 19, 2006 3:21 PM
  • Hello again,

    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! :)
    Thursday, January 19, 2006 3:21 PM
  • You should set you Debugger in VS2005:

    Tools->Options

    Debugging->General

    uncheck option "Suppress JIT optimization on module load"

     

     

    Monday, January 23, 2006 11:12 AM
  • Thanks, I will try that!
    Wednesday, January 25, 2006 10:24 AM
  • Thank you for your suggestion, however this didn't help me in my case.

    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!
    Wednesday, August 16, 2006 10:22 AM
  • 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.

    Tuesday, August 22, 2006 7:02 AM
  • i have a very close similiraty with your prob..and am not getting any solutions yet..if u have already resolved yours, i would very much appreciate it if you post it here..so that i may also refer:)..thanx
    Friday, September 15, 2006 2:44 AM
  •  DejanR wrote:

    You should set you Debugger in VS2005:

    Tools->Options

    Debugging->General

    uncheck option "Suppress JIT optimization on module load"

     

     

    am using VS2005 and i can't seem to follow this navigations..or are u missing something?

    Friday, September 15, 2006 6:13 AM
  • I can see that option ok (using VS2005).
    Friday, September 15, 2006 8:37 AM
  • 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!

    Monday, September 18, 2006 2:13 PM
  • I have debugged similar problems in the past and it can be very frustrating. The problem is typically caused by some component (typically unmanaged, but can also be a bad P/Invoke signature) that corrupts the program's memory. You often see differences between debug and release builds because debug builds contain extra metadata to assist in debugging. In debug mode, the corruption will kill some debug metadata, which will only cause you to see spurious debugging information, but not cause the program to crash. In release, the debug data is not present and the error overwrites critical data such as return addresses, which will cause the program to crash. You will also see small changes (like changing compiler optimizations, or re-ordering instructions) cause code to start working. What you've done is mask the problem. The memory corruption is still occuring, it's just not occuring to a critical piece of memory such as a return address. You will likely see it re-appear later as you continue modifying the code.

    This is honestly a brutal class of problems to diagnose because they're only present when you don't have debug information. Some suggestions:
    1. Try turning on all optimizations, run the program under the debugger, and see if the error occurs. (Typically all optimizations are turned off in debug mode so that debugging is easier.) This will at least give you a way to reproduce the error when you have more debug information. This honestly won't help you a whole lot because by the time you crash, the method call that corrupted the memory is long gone.
    2. Look at all unmanaged code that you're calling: COM objects, C/C++ DLLs, Win32 calls, etc. Check the P/Invoke signatures and COM interop thunks for all unmanaged code to verify that they're correct. Don't trust P/Invoke signatures that you find on the 'net. They're not always correct. Verify for yourself that your data types and parameter orderings are correct.
    3. Try removing the unmanaged code (stub out the calls) and see if the problem goes away. If it does, investigate the component to verify that it is free of memory leaks. (Note that you might only be masking the problem as you re-arrange code.)
    4. Try running your code under a unmanaged memory checker like Compuware BoundsChecker, which will look for memory leaks and access violations. This will likely give you some hints as to which unmanaged component is misbehaving.
    Hope that helps. Good luck finding the root cause.
    Monday, September 18, 2006 5:49 PM
    Moderator
  • I get this error in VS.net 2005 (c#) when adding a query to a strongly typed dataset table adapter.

    The query is for an Access database table with the following structure:

    Id int,
    Name text

    The query is (and it works fine in Access):
    SELECT Id, Name, ID & " - " &  Name as IdName
    FROM Table

    The Table Adapter Configuration Wizard gives me that same weird error and if I then press Finish, Visual Studio just crashes.

    This is my connection string: Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\Database.mdb

    Does anyone have an idea what is causing this and how to solve it?

    Friday, October 13, 2006 3:47 PM
  • Well, when I was asking questions on the C++ forums, when someone mentioned a problem like this, where it would work when run in the debugger, but fail outside of it, in 100% of the cases, it turned out to be a function-local array being over run.

    It should not be possible to do that in managed code, but it's quite easy in non-managed code (ie, your COM object), so that's what & where I'd look.

     

    Friday, October 13, 2006 4:19 PM
  • Hey guys,

    I a getting the exact same error as this everytime I try an edit the query on a tableadapter. Bloody frustrating, I have to write the query in SQL (so I can test) the paste contents into query builder. Every other part of visual studio is fine excpet the query designer.

     

    Cheers

    DAMIEN

    Wednesday, October 18, 2006 10:21 AM
  • Try check Show all settings option on the bottom of that window. Noy you should see Debugging...
    Thursday, November 16, 2006 10:46 AM
  • I to get this error random in my completly managed code. Using Oledb I write to an Excelsheet.

    Stacktrace mentions this "System.Data.Common.UnsafeNativeMethods.IRowset.GetData(IntPtr hRow, IntPtr hAccessor, IntPtr pData)"

    Any help will be appreciated.

    Thanks,

    Karthik

    Wednesday, November 29, 2006 3:20 PM
  • Hello Dear Friend

    Your problem is genuine. And since it is problem , it has a soluton too. The solution lies with you ;only you need to look at it in a different view. I have faced the similar problem  and took me weeks to solve it.

    The main cause behind it lies to the highly enhanced security features of .NET framework 2.0 over .NET 1.1. It has imposed several restiction , policies and permission sets for accessing the data from the web application, It uses full trust as well as partial trust.

    1)  If you try to access the data you don't have permission too or if the source is not trusted it gives the above exception. You not only have to give permission to your application to access the source BUT  you need to make the source as trusted one too.

    2)Also, the other main cause is that , if you try to read the data that is not available, it gives the above exception.

    So its time now to revise your concepts about CAS and permissions in visual studio.NET 2005 which is highly advanced than .NET 1.1.

     For details click the link  below http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetsec/html/foundstone.asp

    Go thro it docs and decide which permission your application requires and implement it.

    Best of Luck.

    mail me a thank you if you are benefitted by this post.

    Balaji Birajdar

    balaji.birajdar@iopsis.com

    Saturday, December 23, 2006 4:51 AM
  • For reference I faced the same problem when by mistake I tried to run ASP 1.1 Application under ASP 2.0 the solution was to go to IIS anc change ASP version back to 1.1.
    Monday, December 25, 2006 7:10 AM
  • I have got the same error, but only on one machine. The program is installed on 90 different PC's and only one have got that problem.
    Friday, February 09, 2007 11:57 AM
  • There should be a checkbox that says "Show all Settings"

    Make sure is cheded, then follow the instructions below:

    You should set you Debugger in VS2005:

    Tools->Options

    Debugging->General

    uncheck option "Suppress JIT optimization on module load"

    Thursday, April 05, 2007 6:27 PM
  • There should be a checkbox that says "Show all settings"

    Make sure it's checked, then follow the instructions below:

     

    You should set you Debugger in VS2005:

    Tools->Options

    Debugging->General

    uncheck option "Suppress JIT optimization on module load"

    Thursday, April 05, 2007 6:28 PM
  • Hi,

    I am trying to access Win API "Comdlg32.dll" functions for "Save As" Dialog box.

    I am getting the same error when accessing the function aht_apiGetOpenFileName(OFN)

     

        Declare Function aht_apiGetOpenFileName Lib "comdlg32.dll" _
            Alias "GetOpenFileNameA" (ByVal OFN As tagOPENFILENAME) As Boolean

     

    Could you let me know, what can be the possible reasons for the same.

     

    I am accessing these functions from a web form.

     I have unchecked the mentioned option in VS2005.

     

    Thanks

    Ashish Jain

    Monday, May 07, 2007 2:29 PM
  •  

    I am using orcas beta 1 and i working with Compact Framework 3.5.

    When i try to access the .sdf database ,the error shown as

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

     

    It only happens when this is running inside cab.

    the sugested solution does not work for me.

     

    please help.

    Monday, May 21, 2007 6:33 AM
  • This works fine in my local machine....but whenever I'm going to access the Application from different system over the network it throws the same exception.

    Now how should i remove that?
    Tuesday, June 12, 2007 7:41 AM
  • Not sure if you are still listening to this post - but your solution helped me at a critical moment.  I would never have found it in time.

    Thanks heaps!!!
    Sunday, June 17, 2007 11:36 PM
  • I had to declare my problem-DLL as  "runtime library - Multi-threaded Debug DLL" instead of "Multi-threaded DLL". Don't ask me why.... Smile

    Al S

    Tuesday, June 26, 2007 2:36 PM
  • I've read through the thread and also checked few similar links in google. Seems like lots of people are having this problem in various scenarios, but it is not clear to me what is the solution to the problem.
    Tuesday, July 10, 2007 12:30 AM
  • I got the same message

     

    Office 2007 Professional (12.0.4518.1014)

    VisualStudio 2005 (8.0.50727.42)

    As a newbee i thought everything which is required to generate managed code for Infopath 2007 with VS 2005 would be available.

    But when i tried to open a new project in VS 2005 using a blank infopath template i got the message

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

     

    After installing

    everything worked fine. 

    Thursday, July 12, 2007 12:53 PM
  • This can occur when you are using a COM component that is not compatible to run under x64 envoirnemnt. So, if you change the Plateform Target to x86. It will not raise this error. I have got this error once using an activex dll and I was able to remove this error by compiling my project in x86 plateform mode. Just go to project properties and selecte x86 instead of Any Plateform in Target Plateform field.
    Wednesday, July 18, 2007 7:10 AM
  •  

    In my case, I rec'd this error when running compiled version. When running it in debug mode, I got a different error message, which was "COM object that has been separated from its underlying RCW cannot be used." It occured because I was querying a COM object property after I had released the object. (InteropServices.Marshal.ReleaseComObject)
    Wednesday, August 01, 2007 9:53 PM
  • I had this error and after lots of searches, I found the particular solution for my problem. I had a datagridview that had a combo-box column, a button, a text-box, etc. What I wanted was to show the new added row, so the user wouldn't have to scroll over and over. I realized this through CurrentCell property of datagridview.
    What caused that strange error was this: first I set the current-cell one of the cells of the last row (to have showed that row) and then set the current-cell to the text-box cell of the actual row (pre-last), so the user would write directly the next value.
    This code worked for some time. Then suddenly, started to generate that error. As on my project work other people too, I'm not sure if something changed.
    Anyway, the solution was: NOT TO SET CurrentCell to the text-box - but to the combo-box cell.
    Weird enough.
    I know this addresses to very specific problem, but I thought someone might just need this information.
    Wednesday, August 08, 2007 12:44 PM
  • I have faced the same problem in my asp.net web application. I have solved this by giving permissions to my bin folder where one of the ddl is present that is referenced from my project.
    Thursday, October 18, 2007 5:10 AM
  • Drew,

     

    Did you ever find an answer to this?

     

    I too have the exact same problem.  When we make calls to objects from a COM DLL, randomly it throws this error.  And it may be only on 1 machine.  I know this error is new with the 2.0 framework and from reading its description in the MSDN help, it seems that it gets thrown when entering into unmanages (COM) code.  Seems to be up to the framework to decide it it is going to potentially run into memory allocation issues.  So that may be the computer dependent factor.

     

    Ayway, I have read all the posts and nothing is working.  Any thoughts would be much appreciated!

    Friday, October 19, 2007 3:36 PM
  • This is my First Post,

    when I am closing my windows form, I got the same exception as that of you. I tried to get rid off by uncheck the suppress JIT in debugger setting, But it didnt work for me.

    I tried by using me.dispose method of the form closing event. It works fine. ie. it didnt show any exception.

    I hope it helps somebody encountering the same problem.


    NOTE:

    For showing this Form, I had used formname.showdialog. If i use formname.show(), there exception wont come.


    Friday, January 04, 2008 1:58 PM
  • Hey there. I can help MAYBE some of you guys.

    I just wanted to say that I also encountered the same error in development of a program. In this context, I was using the Font.DrawText() function under Direct3D. If I send it a string that has an endline as the first character (i.e. string temp = "\njibberish") then I will receive that error during runtime. If say I remove it (string temp = "jibberish") then the error will be cured. However, then one asks what to do if one wants that endline character? Well the best answer I can come up with is to use a space before the endline (string temp = "_\njibberish" where "_" is replaced with the space character).

    That's it. Sorry if this doesn't help with solving another problem :(

    First!!
    Monday, June 30, 2008 9:43 PM
  • Make sure you are not accessing any variables that require a lock.  I run into this sometimes when I forget to get a lock and try to access a shared resource.  IE: on a GUI thread displaying a shared variable while a background thread is locking and updating it.
    Tuesday, November 18, 2008 11:05 PM
  • Hello,

    I am getting this error as well and was wondering if anyone could help (this also may provide some insight for others).  Here is the situation:  I am trying to make a custom shell folder using the Windows Platform SDK 6.0 (for Windows Vista).   I am using DevStudio 2005 (language is all C++ for this project).  I could not get the SDK code to compile from a .NET project at all so I started an empty project and followed the example in the samples that shipped with the sdk to get the job done but wanted to add a user interface and the MFC interface isn't available for an addon (at least when adding something to the project).  So I added a class class that uses .NET even though the project itself uses unmanaged code.  It compiled fine.  So far so good.

    After compiling, my code threw a bad error and in debugging I realized it was because one of the variables in one of the structures declared in the SDK library and used when trying to register the new shell folder was evaluating to "Error: cannot obtain value."  EVERYTHING was being declared and initialized correctly (I more than triple checked).  After experimenting a little (I went back to an earlier experiment in which I had not added the UI and several other things and tried compiling both with and without the /clr option) I got it to work as long as /clr was not checked.  So apparently the SDK code is incompatible with the common language runtime (/clr option for compiling).  That REALLY ticked me off since I had spent the better part of a weekend writing code using libraries that are apparently incompatible for a fairly simple project.

    Not willing to lose my work I decided a compromise might be in order:  I created an external unmanaged DLL that could be compiled without the /clr option and whose functions could be imported.  NOW the variable initialization works fine.  Everything works great right up to the last essential step.  As soon as I call the function to create the folder I get this "weird" error.  Since virtual (shell) folders use COM it might be the problem that no one so far has been able to solve (calling an external COM Function) since my exe calls a DLL function with in turn calls a function that deals with COM.  Has anyone else solved this problem or heard that you cannot use aspects of COM when using .NET? 
    Wednesday, February 11, 2009 12:15 AM
  • OK...lol Never mind solved my own problem.

    For whatever it is worth though, I still think there is an issue.  I found the problem was that the ZeroMemory (and the SecureZeroMemory function) were not working properly.  I was getting returned variables full of a repetitive CDCDCDCDCD (hex) pattern rather than zeros.  So one variable within the KNOWNFOLDER_DEFINITION Structure (the one that I mentioned above that was not working when compiling with /clr) that is optional was a string (LPWSTR) pointer to CDCDCDCD rather than an actual null pointer (indicating that it was not being used). 
    Wednesday, February 11, 2009 4:23 AM
  • I got same problem.....

    $exception {"Attempted to read or write protected memory. This is often an indication that other memory is corrupt."} System.Exception {System.AccessViolationException}

    Any help will be appreciated....I am using VB6 OCX which might try to access memory location in its DLL but not sure...

    I also tried DEP as described in below website...but no use....
    http://jtstroup.net/2008/10/17/AttemptedToReadOrWriteProtectedMemoryThisIsOftenAnIndicationThatOtherMemoryIsCorrupt.aspx

    Any help???




    Thursday, May 21, 2009 3:40 PM
  • Hello Dejan .

    I have already done with the soultion which u have provided. but still, i am facing the problem while do connectivity with Oracle and .NET 2.0.

    Please provide solution. I have to developed application on urgent basis.. pls.


    Thanks,
    Niku Shah
    Tuesday, May 26, 2009 9:48 AM
  • Hi,
    I ran into the same problem. The instruction that causes the exception is oledbadapter.fill when the datatable contains spatial data (mdsys.sdo.geometry).
    I haven't found a solution yet. Just lost about a day figuring out what the problem was.
    Hope this help.
    Pasx
    • Proposed as answer by Webster354 Friday, July 24, 2009 9:37 PM
    Wednesday, June 10, 2009 6:58 PM
  • Drew,

     

    Did you ever find an answer to this?

     

    I too have the exact same problem.  When we make calls to objects from a COM DLL, randomly it throws this error.  And it may be only on 1 machine.  I know this error is new with the 2.0 framework and from reading its description in the MSDN help, it seems that it gets thrown when entering into unmanages (COM) code.  Seems to be up to the framework to decide it it is going to potentially run into memory allocation issues.  So that may be the computer dependent factor.

     

    Ayway, I have read all the posts and nothing is working.  Any thoughts would be much appreciated!


    I had a very similar issue to this poster.  I was able to resolve the problem by changing the target framework for the application from .NET Framework 3.5 to .NET Framework 2.0.  Also, verify the target platform that you're building on.  Building on Any CPU on a 64bit machine resulted in a lot of debugging headaches.  Make sure you select which platform you need, which in my case was x86.
    Friday, July 24, 2009 9:44 PM
  • This is happening to me in debug.  The code is calling one of ESRI's wrappers around their one of their Com Component.  Dejan answer did not work.  Wardog the com component is built by ESRI so I can't search those dll's.  James Kovac's answer does not seem to apply as ESRI built assembly wrappers around their COM components.  I also could not find an entry in tools or the project properties to "turn on all optimizations" Although the exception message is the one cited above, the output window contains the text;

    Step into: Stepping over non-user code 'System.AccessViolationException.AccessViolationException'
    A first chance exception of type 'System.AccessViolationException' occurred in TestDrapeApplication.exe
    'TestDrapeApplication.vshost.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\System.Configuration\2.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.

    Some threads have stated to ensure that system has rights on directory.  I gave "Everyone" full control rights to the directory. No solution

    Some threads have stated that this is a DEP exception and that DEP should be disable for Visual Studio.  That was done as well, No solution.
    Belaji probably has the answer but he gave no indication on how to set those permissions on the application.  Nor as far as I could see did the page he referenced.

    Anonymous12994 merely repeated Dejan's answer  Kongen solution will not work as it is not my Com Component..

    Other sites stated to turn off DEP for Visual Studio.  Did that. no help.
    Webster354 idea of setting project from 3.5 to 2.0 is not helpful as project is already running as 2.0.

    ESRI's forums came up with a number of solutions from ensuring the permissions on the affected directories to ensuring the parameters passsed to their wrapper for their COM object are correct.  None of these worked.

    Surely after all of the traffic this problem has generated on the web, a standard solution has been devised to this problem.


    ERJ MCSD MCDBA
    Thursday, August 27, 2009 6:22 PM
  • Thanks James. 

    This is the first coherent explanation of this error I have seen.  I am having this issue when invoking a managed (ado.net 2.0) wrapper over an unmanaged Sybase Driver.  I'm pretty sure it is a driver issue.
    Michael Dausmann
    Friday, September 04, 2009 4:17 AM
  • I ran into similar problem but after too much research I found out that problem was something very different. I had set the Impersonation =  true in web.config and IBM Db2 on my windows 2003 server didnt have permissions for all users. I just set it to false (or remove it) and my application started working.

     I hope this helps..

     

    Monday, September 07, 2009 5:58 PM
  • Hello.

    Good day.


    I get teh same problem at my C# code.(COM object DLL from C++ DLL)


    I tried.... 
    I configured my VS2005 followed below guide. But the method did not resolve the problemin.
    Tools->Options
    Debugging->General
    uncheck option "Suppress JIT optimization on module load"

    I tried...
    I find the support article from MSN and Downloed the Hotfix (KB923028). And i want to install the Hotfix (NDP20-KB923028-X86.exe) to fix it. But i can't install successfully.
    Error says: The upgade patch cannot be installed by the Windows Installer service because the program to be upgraded may be missing, or the upgrade patch may update a different version of the program. Verify that the program to be upgraded exists on your computer and that you have the correct upgrade patch.
     THen i find the belwo URL link:
    http://code.msdn.microsoft.com/KB923028/Thread/View.aspx?ThreadId=585
    The problem still opened !!


    Is there any guide to resolve my problem. Thanks a lot in advance.

    BR!
    Nano.
    // OS: Windows XP Pro SP2 IDE: VS2005 Pro & .NET: V2.0
    Wednesday, October 14, 2009 2:55 AM
  • Im having the same problem here. But im using a C# COM-Interop Dll to fire events in a Excel RTD DLL maded in VB6... How to solve this ?
    Thursday, October 15, 2009 7:44 PM
  • hey Nano, did u get any solution for this ???

    I have the same problem looks like.

    Am accessing an ocx (which is developed in VC) from my c sharp application

    Thanks.
    Tuesday, October 20, 2009 8:27 PM
  • hey Nano, did u get any solution for this ???

    I have the same problem looks like.

    Am accessing an ocx (which is developed in VC) from my c sharp application

    Thanks.

    @R.nair.

    Not yet.

    The issue still happed at my laptop sometime. (Not every time)
    And the issue won't happend at my teammate's laptop.

    We using the same code which download from ClearCase server.

    I will keep on trace it. 
    I won't try to install a new OS. I really want to find the root cause.

    And any progree from my side, i will update here. 
    And i also hope get some suggestions form others.

    Thank you. 

    BR!
    Nano 
    // OS: Windows XP Pro SP2 IDE: VS2005 Pro & .NET: V2.0
    Wednesday, October 21, 2009 3:04 AM
  • @R.nair,

    After the the service of "Com+ System Application" from Manual Started to Auto Started. (DllHost.exe)

    And i tested several times, Better than befor,

    I am keeping on monitoring it...


    BR
    Nano
    // OS: Windows XP Pro SP2 IDE: VS2005 Pro & .NET: V2.0
    Monday, October 26, 2009 1:06 AM
  • I managed to solve the problem for the following error:

    "An error occurred creating the form. See Exception.InnerException for details.  The error is: Attempted to read or write protected memory. This is often an indication that other memory is corrupt."

    This issue I was having was that I was getting the error when running the compiled EXE file, but not when running it within Visual Studio 2005.

    In the "Solution Explorer" right click the project and choose "Properties". Then click on the "Debug" tab and at the bottom make sure you have a tick in the "Enable unmanaged code debugging" box.

    This will then perform the same in Visual Studio as it does when running the EXE file, so you will receive the error in Visual Studio now as well.

    I was working with the Novell GroupWise COM object "Interop.GroupwareTypeLibrary.dll" and in my form class I was doing...

    Dim gwApplication As New GroupwareTypeLibrary.Application2

    I then realised it should be...

    Dim gwApplication As GroupwareTypeLibrary.Application2

    (Notice I have taken out the "New").

    Now the project compiles fine, with no errors and I can run the EXE fine.

    I would check each statement that you refer to the DLL in and you will probably find the answer to your specific problem.
    Thursday, January 14, 2010 2:31 PM
  • Dear Balaji, 
    I have come across this error while developing a .net web application using access, specifically, when a user navigates a link from a master page to a detail .net page. I understand this is a Visual C forum but I cannot find this error reported anywhere else. From what I can understand,  your post indicates it has something to do with permission settings, am I correct in saying that? Are the permissions setting to be changed on the Access Database or within .net? My knowledge on .net is limited, I am proficient at developing web applications but this error has stumped me...can you help?
    • Proposed as answer by Ross Brigoli Wednesday, April 14, 2010 9:38 AM
    Saturday, March 13, 2010 3:19 PM
  • This is my First Post. I am having the same issue with one of my client's application. It's happening in production environment intermittently and seems to have something to do with System.Windows.Forms at the moment where a managed code is communicating with the Windows UI layer.

    This is very frustrating as I cannot re-create the issue in my IDE. It seems that the error happens only in a specific machine/desktop.

    Has anyone figured out the root cause?

     

    thanks,

    Ross

    Wednesday, April 14, 2010 9:42 AM
  • I got the same exception but only on 64 bit platform. here is my experience...

    http://archistance.blogspot.com/2010/05/exception-attempted-to-read-or-write.html

     

     

    Wednesday, May 05, 2010 9:08 PM
  • I got the same exception but only on 64 bit platform. Click Here for my experience
    Wednesday, May 05, 2010 9:18 PM
  • Experienced the dreaded protected memory issue on a project that was previously working fine in IDE.  I applied NavdeepBhardwaj's suggestion regarding changing compile target to x86 from "AnyCPU".  Also perfomerd a "Clean Build"  and rebuilt project.  So. not sure which fixed it for me.  But have gotton rid of this issue (for now).

    Good luck all.

    Friday, June 18, 2010 4:13 PM
  • Looks like it was more than this.  Problem came back... I looked at more posts further on down this discussion and justinclarke seems to have solved it for me.  I had to check the "Enable unmanaged code debugging" in project properties / Debu area.

    good luck all

    Friday, June 18, 2010 4:37 PM
  • Hi All,

    I had the same problem, in my case it was due to delete action in the unmanaged code which tried to delete none heap code.

    Foo a;

    delete a;

    This causes the acception, once it was solved everything was working properly.

    Tuesday, June 29, 2010 7:50 AM
  • am using visual studio 2010 and i get the same message error  while executin my C++ application.
    i've tried your suggestion but it doesnt work
    any other suggestions?????
    Thursday, July 08, 2010 8:30 AM
  • it should be...

    SELECT Id, Name, ID + ' - ' +  Name as IdName
    FROM Table

    is it not?

     


    Ramanathan
    Sunday, September 05, 2010 6:17 PM
  • anyone got a solution? I'm using multi threads, in each thread, I use a web browser control. this "

    Attempted to read or write protected memory"

    pops up randomly. the exception detail is:

       at System.StubHelpers.InterfaceMarshaler.ConvertToManaged(IntPtr pUnk, IntPtr itfMT, IntPtr classMT, Int32 flags)

       at System.Windows.Forms.UnsafeNativeMethods.IHTMLDocument2.GetLocation()

       at System.Windows.Forms.WebBrowser.get_Document()

    ......

    I tried all the suggested solution, but, still has this problem.

    Wednesday, October 06, 2010 5:36 AM
  • I encountered the same error as Kobrowsky, using an Access database and Visual Studio 2008. I got the error whenever I either tried to view objects (tables, etc.) in the database using the server explorer in Visual Studio or when trying to build a query in VS. VS did not crash for me.

    The error started after I made some changes to several queries in the Access database. Compacting and repairing the database did not help. All of the data was viewable in the database when using Access. The new database queries had parameters. (I was trying to pass values to the parameters in the database query.) I don't know if this was the cause of the problem, but the error started only after I tried to use one of these queries. (The data source of the table adapter was one of these queries.)

    I solved the problem by replacing the database with a backup made before creating the new queries, and deleting the table adapter in the visual studio project. The error then went away. Then I imported the new queries into the backup database that I was using (from the database that had been causing the problem) and removed the parameters from them. Still no error. I recreated the table adapter and everything worked (except for the parameters, which I did not add back in).

    Hope this helps.

    Sunday, November 07, 2010 6:24 AM
  • I am encountering the same error, but different conditions:

    1. older projects load just fine. 

    2. Any project that I create now will get this errori if I attempt to either run the program, or even view web page (tried with a simple html file). 

    3. Error only occurs in Asp.net applications. Windows apps are fine. 

    4. I've tried every applicable solution on this page. 

    5. The IDE seems to be acting odd to me for asp.net pages:  if I add an asp:label for example, the IDE underlines the id code and offers the "use ctrl + click to follow the link.  I don't know whether that is related or not, but I get those errors.

    TIA,

     

    Ron

    Sunday, December 19, 2010 3:27 AM
  • One possible solution is to go to project properties -> application and then CHECK "Enable application framework ".
    Tuesday, December 21, 2010 9:10 AM
  • I had same issue "Attempted to read or write protected memory...." using Acrobat Interapplication Communication" com dll.

    Application was initially made having Acrobat 7.0 installed. Above error ocurred when using application on machine using Acrobat 6.0 installed. Upgrading to Acrobat 9.0 resolved this issue.

    So in addition to permissions, other factors having proper COM dll version matters.

    Tuesday, December 21, 2010 6:18 PM
  • One instance in which this can happen is related to having Oracle 11g installed and using the System.Data.OracleClient Microsoft provides.

    If you revert back to Oracle 10g it will work...or if you solve the miriade of problems the ODP.NET drivers have you'll be fine as well.

    Friday, February 25, 2011 2:12 PM
  • Hi all,

    I just faced the same problem "Attempted to read or write protected memory...." while calling a C++ dll.

    In order to solve the issue I had to change "Platform target" from x86 to "Any CPU" (I'm working on a 64bit PC). Strange enough I experienced it after switching from VS2008 to VS2010 (it seems like VS2010 changed the "Platform target"-switch...)

    Friday, March 04, 2011 3:30 PM
  • Hi All,

    I too got this error on .net framework 3.5 "AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt". Any workaround is available for this issue...???

    Tuesday, March 22, 2011 12:18 PM
  • Add me to the list of "PROTECTED MEMORY" errors... could a windows update have forced a change to the environment here?  Using VS2005.
    Thursday, April 14, 2011 7:07 PM
  • Ok, so here's mine to add to the pile...

    First of all, while I am an experienced programmer, I am new to the world of Windows programming (seems to be a scary world indeed).

    I am using VS2005 C++ on  64-bit AMD processor, and am running Vista. I am trying to run a small example program that uses the MySQL C++ connector, and am getting the following:

    Unhandled Exception: System.AccessViolationException: Attempted to read or write
     protected memory. This is often an indication that other memory is corrupt.
       at std.operator<<<char,struct std::char_traits<char>,class std::allocator<cha
    r> >(basic_ostream<char\,std::char_traits<char> >* , basic_string<char\,std::cha
    r_traits<char>\,std::allocator<char> >* )
       at std.<<(basic_ostream<char\,std::char_traits<char> >* os, SQLString* str) i
    n c:\program files\mysql\mysql-connector-c++-noinstall-1.1.0-win32-vs2005\includ
    e\cppconn\sqlstring.h:line 208
       at ?A0xdfc5429b.retrieve_dbmetadata_and_print(Connection* dbcon) in c:\users\
    gavin\documents\visual studio 2005\projects\test1\test1\test1.cpp:line 72
       at main(Int32 argc, SByte** argv) in c:\users\gavin\documents\visual studio 2
    005\projects\test1\test1\test1.cpp:line 191

    It looks like it's related to the use of the std::string in the std::SQLString class. I also get the following warnings at compile time that are a bit suspicious:

    1>Compiling...
    1>Test1.cpp
    1>c:\program files\mysql\mysql-connector-c++-noinstall-1.1.0-win32-vs2005\include\cppconn\sqlstring.h(36) : warning C4251: 'sql::SQLString::realStr' : class 'std::basic_string<_Elem,_Traits,_Ax>' needs to have dll-interface to be used by clients of class 'sql::SQLString'
    1>        with
    1>        [
    1>            _Elem=char,
    1>            _Traits=std::char_traits<char>,
    1>            _Ax=std::allocator<char>
    1>        ]
    1>C:\Program Files\MySQL\mysql-connector-c++-noinstall-1.1.0-win32-vs2005\include\cppconn/exception.h(59) : warning C4251: 'sql::SQLException::sql_state' : class 'std::basic_string<_Elem,_Traits,_Ax>' needs to have dll-interface to be used by clients of class 'sql::SQLException'
    1>        with
    1>        [
    1>            _Elem=char,
    1>            _Traits=std::char_traits<char>,
    1>            _Ax=std::allocator<char>
    1>        ]
    1>Linking...
    1>Embedding manifest...
    1>Build log was saved at "file://c:\Users\Gavin\Documents\Visual Studio 2005\Projects\Test1\Test1\Debug\BuildLog.htm"
    1>Test1 - 0 error(s), 2 warning(s)
    ========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

     

    Any help is appreciated.

     

    Gavin

    Saturday, May 14, 2011 1:05 AM
  • With so many people having so many problems with this bizare error and this thread going back 4 years now, why has there not been a fix for this?

    For darn near a week, I have had this same error.  Visual Studio 2008, very straight forwad painting a windows form with a tab-control from a single table.  The form displays, you can edit the first field, but as soon as you [tab] or [enter] to another field... BAM!

    I have reinstalled VS.  I have removed all related MS programs and reinstalled VS.  I have rebuilt the form.  I have started the project over.  Needless to say, this is getting old.

    VS 2008 - VB, MS Access DB, simple interface class, OLEDB:

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    Private Sub Proj_Display()
            Try
                txtprj_uid.Text = project.prj_uid.ToString
                txtprj_short_name.Text = project.prj_short_name
                txtprj_name.Text = project.prj_name
                txtprj_description.Text = project.prj_description
                txtprj_notes.Text = project.prj_notes
                txtprj_url_site.Text = project.prj_url_site
                txtprj_url_admin.Text = project.prj_url_admin
                txtprj_login.Text = project.prj_login
                txtprj_password.Text = project.prj_password
                txtprj_add_date.Text = project.prj_add_date
                txtprj_edit_date.Text = project.prj_edit_date

                project = Nothing
            Catch ex As Exception
                clsExceptions.ErrorHandler(ex)
            End Try

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    Other than using some other development environment, Any ideas?  Thanks!



    Sunday, May 15, 2011 11:25 PM
  • Alan,

    AccessViolationException is a low-level exception which indicates that an unmanaged pointer is trying to access memory that it doesn't have the permission to do. There are countless scenarios where this could happen. This error is not specific to any product or technical area and therefore there's no generic fix for it.

    For pure managed applications (.NET applications) you are not likely to create AccessViolations from your own code since the GC handles all the low-level memory allocation and deallocation for you. However, when you mix in external compnents and/or unsafe code such as calls to native DLL:s (p/invoke) these errors could easily happen if you got something wrong.

    From your post I'm having trouble determine if the error comes from VS or from running your application. Have you tried running the application outside VS? Have you tried the same repro steps on another computer?

    Instead of extending this thread any further I'd suggest that you create a new thread and ask about your specific problem there.

    /Calle


    - Still confused, but on a higher level -
    Monday, May 16, 2011 8:28 AM
  • I have a managed C++ application (VS2010) that uses a VB6 OCX and was experiencing the same error.  I was stumped for days before I found that the problem with my application was due to the /NXCOMPAT Linker option.  I had to use /NXCOMPAT:NO in order to disable DEP for my application because the VB6 OCX I am using does not support DEP. 

    Hope this helps.

    Tuesday, May 24, 2011 1:58 PM
  • I've come across this error developing a .Net ActiveX control that triggers events. Marking the ComInterfaceType attribute as InterfaceIsDual in the event interface will cause this error message in the IE when the event is called. Using InterfaceIsDispatched fixed it.
    Sunday, July 24, 2011 10:29 AM
  • Will above apply to unmanage code from 2003. use in 2005?
    michael john ocasio
    Tuesday, September 20, 2011 6:38 PM
  • Interesting theory and I am glad that it worked for you, but unfortunatelly for me it didn't.
    Sunday, October 30, 2011 6:01 PM
  • Hi All, I've just converted an app from running on the 1.1 framework to the 3.5 framework and have got this error in a really strange part of the winforms library! When I clear the nodes of a treeview I get the following: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam) at System.Windows.Forms.NativeWindow.DefWndProc(Message& m) at System.Windows.Forms.Control.DefWndProc(Message& m) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.TreeView.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam) at System.Windows.Forms.NativeWindow.DefWndProc(Message& m) at System.Windows.Forms.Control.DefWndProc(Message& m) at System.Windows.Forms.Control.WmWindowPosChanged(Message& m) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.TreeView.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lparam) at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam) at System.Windows.Forms.NativeWindow.DefWndProc(Message& m) at System.Windows.Forms.Control.DefWndProc(Message& m) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.TreeView.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) at System.Windows.Forms.UnsafeNativeMethods.SendMessage(HandleRef hWnd, Int32 Msg, Int32 wParam, IntPtr lParam) at System.Windows.Forms.TreeNode.Remove(Boolean notify) at System.Windows.Forms.TreeNode.Clear() at System.Windows.Forms.TreeNodeCollection.Clear() Oddly, if I replace the call to the Clear() method with a loop that cycles through each node and removes them using RemoveAt() then it works fine. I've inspected the object itself and it looks fine... Any pointers would be appreciated and I have gone through each post in this thread and spent days trawling the web for other clues to no avail! Thanks in advance.
    Friday, January 06, 2012 10:13 AM
  • I had the following error "Attempted to read or write protected memory. This is often an indication that other memory is corrupt."in vsts 2010, I did

    Tools->Options

    Debugging->General

    uncheck option "Suppress JIT optimization on module load" but it did not worked.

    Wednesday, February 15, 2012 10:35 AM
  • I am getting same kind of exception while running Windows Phone App. I tried with:

    Tools->Options

    Debugging->General

    uncheck option "Suppress JIT optimization on module load"

    But it is not working fine, even after doing the above changes! Let us know if anyone have some meaningful solution for this exception. 


    Thursday, August 21, 2014 6:43 AM