Hi All,I am posting here an issue that i observed with NHibernate. Sorry to post here if this is already (if so please redirect me to the same).
Details of my project:NHibernate version used - 1.2
Underlying database - Oracle 11g.
.NET language - C#, .NET Framework - 3.5
Issue:Code:
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
The inner exception is:
An exception of type 'NHibernate.ADOException' occurred in method 'DoList' of class 'Loader'
The stack trace given is:
at NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters) in C:\Documents and Settings\test\Desktop\NHibernate-1.2.1.GA-src\src\NHibernate\Loader\Loader.cs:line 1803
at NHibernate.Loader.Loader.ListIgnoreQueryCache(ISessionImplementor session, QueryParameters queryParameters) in C:\Documents and Settings\test\Desktop\NHibernate-1.2.1.GA-src\src\NHibernate\Loader\Loader.cs:line 1745
at NHibernate.Loader.Loader.List(ISessionImplementor session, QueryParameters queryParameters, ISet querySpaces, IType[] resultTypes) in C:\Documents and Settings\test\Desktop\NHibernate-1.2.1.GA-src\src\NHibernate\Loader\Loader.cs:line 1733
at NHibernate.Impl.SessionImpl.Find(CriteriaImpl criteria, IList results) in C:\Documents and Settings\test\Desktop\NHibernate-1.2.1.GA-src\src\NHibernate\Impl\SessionImpl.cs:line 4963
at NHibernate.Impl.SessionImpl.Find[T](CriteriaImpl criteria) in C:\Documents and Settings\test\Desktop\NHibernate-1.2.1.GA-src\src\NHibernate\Impl\SessionImpl.cs:line 4914
at NHibernate.Impl.CriteriaImpl.List[T]() in C:\Documents and Settings\test\Desktop\NHibernate-1.2.1.GA-src\src\NHibernate\Impl\CriteriaImpl.cs:line 323
The inner exception is:
An exception of type 'System.AccessViolationException' occurred in method 'Read' of class 'OpsDac'
The stack trace given is:
at Oracle.DataAccess.Client.OpsDac.Read(IntPtr opsConCtx, IntPtr opsErrCtx, IntPtr opsSqlCtx, IntPtr& opsDacCtx, OpoSqlValCtx* pOpoSqlValCtx, OpoMetValCtx* pOpoMetValCtx, OpoDacValCtx* pOpoDacValCtx)
at Oracle.DataAccess.Client.OracleDataReader.Read()
at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) in C:\Documents and Settings\test\Desktop\NHibernate-1.2.1.GA-src\src\NHibernate\Loader\Loader.cs:line 440
at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) in C:\Documents and Settings\test\Desktop\NHibernate-1.2.1.GA-src\src\NHibernate\Loader\Loader.cs:line 181
at NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters) in C:\Documents and Settings\test\Desktop\NHibernate-1.2.1.GA-src\src\NHibernate\Loader\Loader.cs:line 1793
Code Accessing NHibernate:I save an object say 'OBJ1' in database using ADO.NET, and then i try to load it from NHibernate, but at this time i get the above reported exception.
Below is the sample code.Code:
public void Main()
{
//Placeholder for saving ID of new record that is saved through ADO.
decimal static ADOSavedObjectID;
ADONewTestRecord obj = new ADONewTestRecord();
//ADO.NET code to save this returns saved object db ID.
ADOSavedObjectID = SaveThroughADO(obj);
//Fetch the Saved record through NHibernate.
TestNewRecordFromNHibernate = GetTestRecordThroughNHibernate(ADOSavedObjectID)
public decimal SaveThroughADO(ADONewTestRecord obj)
{
//ADO code.
}
public TestNewRecordFromNHibernate GetTestRecordThroughNHibernate(decimal ADOSavedObjectID)
{
return LoadNHibernateObject(ADOSavedObjectID);
}
public TestNewRecordFromNHibernate LoadNHibernateObject(decimal ADOSavedObjectID)
{
//NHibernate session is already opened, i am not providing details.
Session.Clear();
IList<TestNewRecordFromNHibernate> results;
ICriteria criteria = Session.CreateCriteria(typeof (TestNewRecordFromNHibernate));
criteria.Add(Expression.Eq("ID", ADOSavedObjectID));
//In this line i get the reported exception see above.
results = criteria.List<TestNewRecordFromNHibernate>();
return results[0];
}
}