简体   繁体   中英

Attempted to Read or Write protected memory

I am a developer trying to bring an old ASP.Net StoreFront website up to date enough so I can get it to run on my local machine. However, I get the issue:

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

I have tried:

  • Disabling JIT
  • Disabling compiler optimizations
  • Forcing x86 platform target
  • Commenting out all loaded assemblies
  • I have updated to ASP.Net 4.5.2

Not only is the website broken on my computer, it is also broken on the production site with the same error.

The website I am working on is proprietary and I am bound by a confidentiality agreement, so I won't be able to post pieces of code. Does anyone have any suggestions?

Edit: I have access to the source code. If I run the project, it throws an error when it runs a method in the Global.asax.cs file. If I comment that out, it just throws the same error with no target.

Edit: 1. No DllImport or unsafe found in the code.

  1. I'm using IISExpress and I can attach to the IISExpress process

    [AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. AspDotNetStorefront.Global.InitializeComponent() in c:\\Dev\\Web\\App_Code\\Global.asax.cs:222] AspDotNetStorefront.Global..ctor() in c:\\Dev\\Web\\App_Code\\Global.asax.cs:35 ASP.global_asax..ctor() in c:\\AppData\\Local\\Temp\\Temporary ASP.NET Files\\root\\47c1f925\\38c0005\\App_global.asax.inuh90ct.0.cs:0

    [TargetInvocationException: Exception has been thrown by the target of an invocation.] System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck) +0 System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache) +86 System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache) +230 System.Activator.CreateInstance(Type type, Boolean nonPublic) +67 System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) +1051 System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) +111 System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +215 System.Web.HttpApplicationFactory.FireApplicationOnStart(Http Context context) +8984344 System.Web.HttpApplicationFactory.EnsureAppStartCalled(HttpContext context) +136 System.Web.HttpApplicationFactory.GetApplicationInstance(HttpContext context) +92 System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr) +289]

This is the error I get if I comment out the function call currently being pointed to as the source:

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

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 


    [AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.]
   System.Web.Mobile.ErrorHandlerModule..ctor() +0

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
   System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck) +0
   System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache) +86
   System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache) +230
   System.Activator.CreateInstance(Type type, Boolean nonPublic) +67
   System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) +1051
   System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) +111
   System.Web.Configuration.Common.ModulesEntry.Create() +39
   System.Web.Configuration.HttpModulesSection.CreateModules() +164
   System.Web.HttpApplication.InitModules() +28
   System.Web.HttpApplication.InitInternal(HttpContext context, HttpApplicationState state, MethodInfo[] handlers) +729
   System.Web.HttpApplicationFactory.GetNormalApplicationInstance(HttpContext context) +298
   System.Web.HttpApplicationFactory.GetApplicationInstance(HttpContext context) +107
   System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr) +289

Solution: ASPDNSF 7.0 is incompatible with ASP.Net > 2.0

http://forumarchive.vortx.com/threads/26485-Attempted-to-read-or-write-protected-memory.html last post

http://knowledge.3essentials.com/web-hosting/article/612/ERROR-Attempted-to-read-or-write-protected-memory.html

they are all pointing at asp.net 3.5 sp1 and .net 3.5 sp1 that is what's causing the attempted to read..... error

  1. As @JonSaunders hinted at in a comment, it seems likely that this is a result of improperly making a call to native code. That would be the first place to check - look for [DllImport and unsafe in the solution for potential problem spots. I've seen this error pop up when, for example, using an unmanaged library that isn't threadsafe.
  2. More to the point, attach the debugger to the w3wp.exe IIS worker process, set a breakpoint at the first statement in the constructor, visit the problematic page, and start stepping through. Use this to find out what call or calls is causing the Access Violation.

To attach the debugger to w3wp, you'll have to make sure you're running Visual Studio as an administrator, and you'll have to be running it on the machine that the website is deployed to. This process should give you a better idea of what is causing the AccessViolation, and allow for better research/question asking.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM