gpt4 book ai didi

c# - NHibernate 在 NUnit 和控制台下工作,但在 IIS 下不工作 [throws PropertyAccessException]

转载 作者:行者123 更新时间:2023-11-30 22:26:31 31 4
gpt4 key购买 nike

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

最佳答案

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

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

关于c# - NHibernate 在 NUnit 和控制台下工作,但在 IIS 下不工作 [throws PropertyAccessException],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11730988/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com