Attempted to read or write protected memory in a .NET application

天涯浪子 提交于 2019-12-10 13:35:50

问题


I'm having troubles at implementing and ASP .Net Application in IIS 6 Server.

When the user tries to open a web page that access the database, iis server throws "Attempted to read or write protected memory" this is the StackTrace:

System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. at Oracle.DataAccess.Client.OpsPrm.ResetValCtx(OpoPrmValCtx* pOpoPrmValCtx, Int32 ctxSize) at Oracle.DataAccess.Client.OracleParameter.ResetCtx(Int32 arraySize) at Oracle.DataAccess.Client.OracleParameter.PreBind(OracleConnection conn, IntPtr errCtx, Int32 arraySize) at Oracle.DataAccess.Client.OracleCommand.ExecuteReader(Boolean requery, Boolean fillRequest, CommandBehavior behavior) at Oracle.DataAccess.Client.OracleCommand.ExecuteReader() at Oracle.DataAccess.Client.OracleCommand.ExecuteScalar() at Tenaris.FSA.OracleProvider.OracleProvider.ExecuteScalar(String commandToExecute, CommandType commandType, DbParameter[] parameters) in C:\Congelados FSA\FSA 1er Entregable 05052013\Tenaris.FSA.OracleProvider\OracleProvider.cs:line 223 at Tenaris.FSA.DAC.Providers.DataAccessManager.ExecuteScalar(String commandToExecute, CommandType commandType, DbParameter[] parameters) in C:\Congelados FSA\FSA 1er Entregable 05052013\Tenaris.FSA.DataAccessComponent\Providers\DataAccessManager.cs:line 59 at Tenaris.FSA.DAC.Repository.AppointmentWayClientDAL.GetCountRegisters(Boolean onlyEnabled) in C:\Congelados FSA\FSA 1er Entregable 05052013\Tenaris.FSA.DataAccessComponent\Repository\AppointmentWayClientDAL.cs:line 39 at Tenaris.FSA.BusinessComponents.BusinessProcess.AppointmentWayClientManager.GetCountRegisters(Boolean onlyEnabled) in C:\Congelados FSA\FSA 1er Entregable 05052013\Tenaris.FSA.BusinessComponents\BusinessProcess\AppointmentWayClientManager.cs:line 28

What's rare, because that error is not supposed to appear in managed code, and the previous version of the site is working fine. I've done several tests, like compiling the app in an x86 platform pc, copied the web.config from the functional version, copied the Oracle.DataAccess dll from the functional version, but the error still showing.

Another thing you should know is that there is a page that, actually succeded in filling a dropdownlist, but then the page has to fill a gridview and there appears the above exception.


回答1:


I could finally solve the issue, another developer used a "using" clause while creating OracleParameters, it was like:

using(OracleParameter prm = SomeMethodThatCreatesIt(value,paramName))
{
 //extracode
 myCommand.Parameters.Add(prm);
}

So the code had to change to:

OracleParameter prm = SomeMethodThatCreatesIt(value,paramName);
//extracode
myCommand.Parameters.Add(prm);

As you can see in the stacktrace, the problem were at some process for parameters.

So, The code was Disposing the object before using it. What I can't understand is why is this even working in a console application that was one of my tests, but well it is working now, Thank you everyone




回答2:


the system has run out of ram to load it so when it tries to take more from other applications that is protected memory so get more ram



来源:https://stackoverflow.com/questions/16573614/attempted-to-read-or-write-protected-memory-in-a-net-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!