我有一个 API,其中包含一个如下所示的对象:
public class NOrgUnit {
public virtual NOrgUnit Parent { get; set;}
public virtual ISet<NOrgUnit> children { get; set; } // an Iesi 1.0.1 ISet
public virtual Int64 Id { get; protected set; }
public virtual string Name { get; set; }
// etc.
}
该对象具有以下地图:
public class NOrgUnitMap : ClassMap<NOrgUnit>
{
public NOrgUnitMap()
{
Id(x => x.Id);
Map(x => x.Name);
References(x => x.Parent).Nullable();
HasMany(x => x.children).AsSet();
}
}
当我构建我的 API 并在控制台应用程序中引用它时,一切正常。
当我在 asp.net 上下文(特别是 sitecore 项目)中引用相同的 .dll 时,我收到 NHibernate 异常:
Org Service encountered unexpected exception [NHibernate.PropertyAccessException: Invalid Cast (check your mapping for property type mismatches); setter of TI.Organization.Core.Impl.DAL.Persistence.Entities.Hierarchy.NOrgUnit ---> System.InvalidCastException: Unable to cast object of type 'TI.Security.Core.Impl.Management.Provisioning.DAL.PersistentGenericSet`1[TI.Organization.Core.Impl.DAL.Persistence.Entities.Hierarchy.NOrgUnit]' to type 'Iesi.Collections.Generic.ISet`1[TI.Organization.Core.Impl.DAL.Persistence.Entities.Hierarchy.NOrgUnit]'.
at (Object , Object[] , SetterCallback )
at NHibernate.Bytecode.Lightweight.AccessOptimizer.SetPropertyValues(Object target, Object[] values)
at NHibernate.Tuple.Entity.PocoEntityTuplizer.SetPropertyValuesWithOptimizer(Object entity, Object[] values)
--- End of inner exception stack trace ---
at NHibernate.Tuple.Entity.PocoEntityTuplizer.SetPropertyValuesWithOptimizer(Object entity, Object[] values)
at NHibernate.Tuple.Entity.PocoEntityTuplizer.SetPropertyValues(Object entity, Object[] values)
at NHibernate.Persister.Entity.AbstractEntityPersister.SetPropertyValues(Object obj, Object[] values, EntityMode entityMode)
at NHibernate.Engine.TwoPhaseLoad.InitializeEntity(Object entity, Boolean readOnly, ISessionImplementor session, PreLoadEvent preLoadEvent, PostLoadEvent postLoadEvent)
at NHibernate.Loader.Loader.InitializeEntitiesAndCollections(IList hydratedObjects, Object resultSetId, ISessionImplementor session, Boolean readOnly)
at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies)
这已经困扰了我好几天了。为什么应用程序可以在控制台而不是 IIS 中运行?