【问题标题】:Nhibernate does not work after upgrade to version 2.1.2升级到版本 2.1.2 后 Nhibernate 不起作用
【发布时间】:2011-03-24 16:07:38
【问题描述】:

我最近将我的 NHibernate 实现从版本 2.1.0 更改为 2.1.2。对于延迟加载,我使用了 LinFu 实现:NHibernate.ByteCode.Linfu。

由于我更改为最新版本,因此出现以下错误:

 [SecurityException: That assembly does not allow partially trusted callers.]
  NHibernate.ByteCode.LinFu.ProxyFactory..cctor() +0

调试时遇到如下错误:

   at NHibernate.ByteCode.LinFu.ProxyFactory..ctor()
   at NHibernate.ByteCode.LinFu.ProxyFactoryFactory.BuildProxyFactory()
   at NHibernate.Tuple.Entity.PocoEntityTuplizer.BuildProxyFactoryInternal(PersistentClass class, IGetter getter, ISetter setter)
   at NHibernate.Tuple.Entity.PocoEntityTuplizer.BuildProxyFactory(PersistentClass persistentClass, IGetter idGetter, ISetter idSetter)
   at NHibernate.Tuple.Entity.AbstractEntityTuplizer..ctor(EntityMetamodel entityMetamodel, PersistentClass mappingInfo)
   at NHibernate.Tuple.Entity.PocoEntityTuplizer..ctor(EntityMetamodel entityMetamodel, PersistentClass mappedEntity)
   at NHibernate.Tuple.Entity.EntityEntityModeToTuplizerMapping..ctor(PersistentClass mappedEntity, EntityMetamodel em)
   at NHibernate.Tuple.Entity.EntityMetamodel..ctor(PersistentClass persistentClass, ISessionFactoryImplementor sessionFactory)
   at NHibernate.Persister.Entity.AbstractEntityPersister..ctor(PersistentClass persistentClass, ICacheConcurrencyStrategy cache, ISessionFactoryImplementor factory)
   at NHibernate.Persister.Entity.SingleTableEntityPersister..ctor(PersistentClass persistentClass, ICacheConcurrencyStrategy cache, ISessionFactoryImplementor factory, IMapping mapping)
   at NHibernate.Persister.PersisterFactory.CreateClassPersister(PersistentClass model, ICacheConcurrencyStrategy cache, ISessionFactoryImplementor factory, IMapping cfg)
   at NHibernate.Impl.SessionFactoryImpl..ctor(Configuration cfg, IMapping mapping, Settings settings, EventListeners listeners)
   at NHibernate.Cfg.Configuration.BuildSessionFactory()
   at MyApplication.SessionManager..ctor() in C:\Projects\MyApps\MyApplication\SessionManager.cs:line 75

这是因为使用了 NHibernate.ByteCode.LinFu 吗?我该怎么做才能让应用程序再次运行?

【问题讨论】:

  • 你是否也更新了依赖库? (林福就是其中之一)
  • 我更新了 Nhibernate.ByteCode.Linfu ,不需要更新 Linfu.DynamicProxy。查看引用的帖子,我也尝试使用 ByteCode.Castle,但这也不起作用。
  • 你确定你的 LinFu 是用部分信任标志编译的吗?您是否尝试过预先生成代理? nhforge.org/wikis/howtonh/…
  • 你终于设法解决/解决这个问题了吗?

标签: nhibernate linfu-dynamicproxy


【解决方案1】:

如果您有不同版本的引用,即 2.1.0 和 2.1.2,您可以配置 .net 以使用程序集重定向将调用从旧版本重定向到新版本,反之亦然...

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
                <assemblyIdentity name="Linfu.DynamicProxy"
                                  publicKeyToken="32cd8f1a53a4c744"
                                  culture="neutral" />
                <bindingRedirect oldVersion="1.0.0.0"
                                 newVersion="1.1.0.0"/>
            </dependentAssembly>
        </assemblyBinding>
    </runtime>
</configuration>

但是我认为这不是问题,因为错误完全不同。即安全例外。 “该程序集不允许部分受信任的调用者”似乎表明任何正在运行的进程都没有必要的上下文权限来执行方法“NHibernate.ByteCode.LinFu.ProxyFactory..ctor()”中的代码。您可能正在使用客户端配置文件或在“部分受信任”的网络托管环境中运行应用程序。

您是否有更多关于运行此应用程序的上下文的信息?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-05
    • 1970-01-01
    • 1970-01-01
    • 2020-04-27
    相关资源
    最近更新 更多