Attempted to read or write protected memory

I began to see that AccessViolationException throws several different points in my application. This never happened on my development computer, our test server. It also appeared on only one of our 2 production servers. Since it only seemed on one of our production servers, I started looking at the installed versions of .net on the servers.


I found that (for some strange reason), the production server that was having problems had 2.0 sp2, 3.0 sp2 and 3.5 sp1, while the other production server and the test server had 2.0 sp1.


My application is intended only for framework 2.0, I decided to remove all versions of the framework from the production server and install only 2.0 sp1. So far, I have not been able to reproduce the problem. Very interesting.

PC development: compact 2.0 sp2, compact 3.5, 2.0 sp2, 3.0 sp2, 3.5 sp1 Control server: 2.0 sp1 Production server1: 2.0 sp1 Production server2: 2.0 sp2, 3.0 sp2, 3.5 sp1

Now, why I cannot reproduce the problem on my development computer with 2.0 sp2, I cannot understand. I heard rumors that this violation of access rights can occur on some software that uses remote access, which does, but violation of access rights never occurs when the switch actually takes place. I am fine using only 2.0 sp1, but I'm really interested to know if anyone had this problem and if they found a workaround for newer versions of the frame.

Here are a couple of exceptions and their stack trace:

System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. at ICSharpCode.TextEditor.TextArea.HandleKeyPress(Char ch) at ICSharpCode.TextEditor.TextArea.SimulateKeyPress(Char ch) at ICSharpCode.TextEditor.TextArea.OnKeyPress(KeyPressEventArgs e) at System.Windows.Forms.Control.ProcessKeyEventArgs(Message& m) at System.Windows.Forms.Control.ProcessKeyMessage(Message& m) at System.Windows.Forms.Control.WmKeyChar(Message& m) at System.Windows.Forms.Control.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.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) System.AccessViolationException: 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.TextBoxBase.WndProc(Message& m) at System.Windows.Forms.RichTextBox.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.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) 
+33
c # access-violation servicepacks
Feb 27 '09 at 20:07
source share
12 answers

I had the same problem. 2.0 worked fine. after installing up to 3.5 sp1, the application receives an access violation.

http://support.microsoft.com/kb/971030 is installed and my problem is resolved, although I do not use LCG.

+12
Jun 09 '10 at 11:44
source share

Microsoft also released a hotfix (July 2, 2007) to prevent the "Attempting to read or write protected memory" error that has been haunting the .NET 2.0 platform for some time now. Take a look at http://support.microsoft.com/kb/923028 - not sure if this applies to you, but thought you could check it out.

+11
May 17 '09 at 23:08
source share

I had the same problem after upgrading from .NET 4.5 to .NET 4.5.1. This command was executed for me:

netsh winsock reset

+10
Dec 10 '13 at
source share

In VS 2013, the .NET Framework 4.5.1 also has an AccessViolationException error (KB2915689) when working with SQL Server / TCP Sockets. Updating to the .NET Framework 4.5.2 fixes this problem.

Reported VS.NET AccessViolationException

Attempted to read or write protected memory. This often indicates that another memory is corrupted.

+3
Dec 30 '15 at 10:40
source share

I used OLEDB and I switched to SQL Client and it solved my problem with this error.

+1
Feb 14 '12 at 17:21
source share

I usually call "Attempt to read or write protected memory" when calling the "Show" method on some WinForms. I checked, and there is nothing special about these forms. I don’t know why this works (maybe someone can tell me), but, as a rule, transferring the code that is executed in the “Load” event of the form to the “Displayed” event corrects it for me, and I’m more of it I do not see.

+1
Dec 03
source share

Make sure you have no threads in threads. What caused this error for me. See This Link: Attempting to read or write protected memory. This often indicates that another memory is corrupt.

+1
Aug 08 '13 at 17:27
source share

In some cases, adding "Option Strict On" to VB.NET and solving all the problems that it finds with the right casting solved this problem for me.

+1
Feb 18 '14 at 23:31
source share

In my case, this was fixed when I set "Enable 32 Bit applications" = True for the application pool on the IIS server.

0
Jun 10 '16 at 10:40
source share

In my case, the fonts used in one of the shared library were not installed on the system.

0
06 Oct '16 at 9:32
source share

The problem may be related to the mixed assembly platform DLLs in the project. ie You create your project on any CPU, but you have some DLLs in the project already created for the x86 platform. This will lead to random crashes due to the different memory mapping of the 32-bit and 64-bit architecture. If all DLLs are built for the same platform, the problem can be solved. For security, try reinstalling the x86 32-bit architecture as it is most compatible.

0
Feb 22 '17 at 4:05
source share

Hi There are two possible reasons.

  • We have managed code, and we call it from managed code. which prevents the execution of this code. try to run these commands and restart your computer

    cmd: netsh winsock reset

open cmd.exe and run the command "netsh winsock reset catalog"

  1. Anti-Virus considers unmanaged code as harmful and restricting the launch of this code, disable the anti-virus , and then check
-one
Oct 20 '15 at 6:29
source share



All Articles