2

我有一个 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 中运行?

4

1 回答 1

3

TI.Security.Core.Impl.Management.Provisioning.DAL.PersistentGenericSet<T>是一个奇怪的类。这是定制开发的吗?如果是这样,它可能不会实现Iesi.Collections.Generic.ISet<T>. 如果它确实实现了它,则可能是加载了多个 Iesi 程序集的问题。

我从来没有听说过sitecore,所以也许那是在后台做一些奇怪的事情。

于 2012-07-31T09:31:14.010 回答