Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 796
Hard Tour Vela Avatar asked May 15 '13 19:05

Hard Tour Vela


1 Answers

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

like image 87
Hard Tour Vela Avatar answered Oct 22 '22 16:10

Hard Tour Vela