尝试读取或写入受保护的内存

时间:2015-06-08 15:52:31

标签: c# asp.net

我是一名开发人员,试图将旧的ASP.Net StoreFront网站更新到足以让我在本地计算机上运行。但是,我得到了这个问题:

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

我试过了:

  • 禁用JIT
  • 禁用编译器优化
  • 强制x86平台目标
  • 注释掉所有已加载的程序集
  • 我已更新为ASP.Net 4.5.2

该网站不仅在我的计算机上损坏,而且在生产网站上也出现了相同的错误。

我正在处理的网站是专有的,我受到保密协议的约束,因此我无法发布代码段。有没有人有任何建议?

编辑:我可以访问源代码。如果我运行该项目,它会在Global.asax.cs文件中运行方法时抛出错误。如果我对此进行评论,它只会抛出相同的错误而没有目标。

编辑:1。代码中没有找到DllImport或unsafe。

  1. 我正在使用IISExpress,我可以附加到IISExpress进程

    [AccessViolationException:尝试读取或写入受保护的内存。这通常表明其他内存已损坏。    c:\ Dev \ Web \ App_Code \ Global.asax.cs:222中的AspDotNetStorefront.Global.InitializeComponent()]    c:\ Dev \ Web \ App_Code \ Global.asax.cs中的AspDotNetStorefront.Global..ctor():35    ASP.global_asax..ctor()在c:\ AppData \ Local \ Temp \ Temporary ASP.NET Files \ root \ 47c1f925 \ 38c0005 \ App_global.asax.inuh90ct.0.cs:0

    [TargetInvocationException:调用目标抛出了异常。]    System.RuntimeTypeHandle.CreateInstance(RuntimeType类型,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(HttpContext context)+8984344    System.Web.HttpApplicationFactory.EnsureAppStartCalled(HttpContext context)+136    System.Web.HttpApplicationFactory.GetApplicationInstance(HttpContext context)+92    System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr)+289]

  2. 如果我将当前被指向的函数调用注释为源,这是我得到的错误:

    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
    

2 个答案:

答案 0 :(得分:1)

解决方案:ASPDNSF 7.0与ASP.Net>不兼容2.0

http://forumarchive.vortx.com/threads/26485-Attempted-to-read-or-write-protected-memory.html 上一篇文章

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

他们都指向asp.net 3.5 sp1和.net 3.5 sp1,这是导致尝试阅读的错误.....错误

答案 1 :(得分:0)

  1. 正如@JonSaunders在评论中暗示的那样,这似乎是由于不正确地调用本机代码造成的。这将是第一个检查的地方 - 在解决方案中寻找潜在问题点的[DllImportunsafe。我已经看到这个错误弹出,例如,使用非线程安全的非托管库。
  2. 更重要的是,将调试器附加到w3wp.exe IIS工作进程,在构造函数的第一个语句处设置断点,访问有问题的页面,然后开始单步调试。使用此选项可以找出导致访问冲突的呼叫或呼叫。
  3. 要将调试程序附加到w3wp,您必须确保以管理员身份运行Visual Studio,并且必须在部署网站的计算机上运行它至。这个过程应该让您更好地了解导致AccessViolation的原因,并允许更好的研究/提问。