ODP.Net – Attempted to read or write protected memory.

Posted by Blake on 3/5/2013
    “AccessViolationException – Attempted to read or write protected memory.  This is often an indication that other memory is corrupt.”

In typical Oracle fashion, the exception thrown doesn’t give you a lot of information to go on and can be caused by any numerous reasons. In our case, there is the ODP.Net assembly Oracle.Data.dll that is a managed wrapper around the unmanaged Oracle libraries that are required to connect to Oracle (with their setup… the main one being that 127MB bloated beast of an assembly – oraociei11.dll). In our case, just having the Oracle package installed on the web server wasn’t enough, we also had to include the managed and unmanaged assemblies in the BIN directory of the site wanting to connect.

If you are missing one of those assemblies, the AccessViolationException will occur. Further, if you then add the correct assembly but haven’t recycled the site it will continue to happen. In our case, getting the assembly list correct and then forcing the site to recycle fixed the problem.