NHibernate QueryException: mismatch type, expected type == actual type

We have this strange problem in a web application when using ActiveRecord 2.0 with NHibernate 2.1.0 (also tried 2.1.2). I apologize if this description is a bit vague, but we are having trouble understanding what is going on. We are working on a large enterprise application where we are trying to isolate the problem and make a small example, but we have not done it yet.

The problem arises when we try to execute a special query on two objects with many relationships. This is the code that will cause the problem:

int testItemId = 1;
TestItem testItem = ActiveRecordMediator<TestItem>.FindByPrimaryKey(testItemId, false);
DetachedCriteria testCriteria = DetachedCriteria.For<TestItemRevision>();
testCriteria.Add(Expression.Eq("TestItem", testItem));
TestItemRevision testRevision = ActiveRecordMediator<TestItemRevision>.FindFirst(testCriteria);

When executing FindFirst (or FindAll), the following exception is thrown: Mismatch type in NHibernate.Criterion.SimpleExpression: TestItem expected type MyProduct.Core.DomainModel.Test.TestItem, actual type MyProduct.Core.DomainModel.Test.TestItem

As you can see, the expected type == is a valid type.

We found that this exception was thrown at NHibernate.Criterion.CriterionUtil.GetColumnNamesUsingPropertyName (...). We compiled our own version of NHibernate, with some additional inputs here. When everything is in order, we get the following:

propertyType.ReturnedClass.Assembly: MyProduct.Core.DomainModel, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
propertyType.ReturnedClass.Assembly.Location: C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\daa38103\4727b73f\assembly\dl3\bb8c85b9\7202540f_a593ca01\MyProduct.Core.DomainModel.DLL
value.GetType().Assembly: MyProduct.Core.DomainModel, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
value.GetType().Assembly.Location: C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\daa38103\4727b73f\assembly\dl3\bb8c85b9\7202540f_a593ca01\MyProduct.Core.DomainModel.DLL

When an exception is thrown, we get the following:

propertyType.ReturnedClass.Assembly: MyProduct.Core.DomainModel, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
propertyType.ReturnedClass.Assembly.Location == String.Empty: True
value.GetType().Assembly: MyProduct.Core.DomainModel, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
value.GetType().Assembly.Location: C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\daa38103\4727b73f\assembly\dl3\bb8c85b9\7202540f_a593ca01\MyProduct.Core.DomainModel.DLL

That is, when an exception is thrown, the expected type has no location and is considered as another assembly.

: . IIS, , 1 3 . , , , . , , , , DLL bin . - Web.config . WinServer 2003/IIS6, Win7/IIS7.5.

, . - , - ?

Edit:

global.asax Application_Start:

Assembly[] assemblies = new[] { Assembly.Load("MyProduct.Core.DomainModel") };
ActiveRecordStarter.Initialize(assemblies, ActiveRecordSectionHandler.Instance);

( , config, .)

+3
1

MSDN , Assembly Location

, , Load (array []), ("").

, , - . Google- , , , , NHibernate .

, , , , - ? . !

+1

Source: https://habr.com/ru/post/1728377/


All Articles