代码之家  ›  专栏  ›  技术社区  ›  Krisztián Balla

nhibernate无法从GAC加载程序集(nhibernate.bytecode.castle和businesslogic)

  •  -2
  • Krisztián Balla  · 技术社区  · 14 年前

    我在网上到处寻找我的这个问题。我找到了一些建议的解决方案,但它们不起作用。

    设置如下:

    我正在使用ActiveRecord/NHibernate。我创建了一个封装ActiveRecord的程序集,名为BusinessLogic。我的想法是,我的所有项目都应该使用业务逻辑,而不是直接引用ActiveRecord/NHibernate。

    我在GAC(.NET的全局程序集缓存)中安装了以下文件:

    • antlr3.runtime.dll业务逻辑.dll
    • 业务逻辑.dll
    • castle.activerecord.dll(城堡.activerecord.dll)
    • castle.components.validator.dll
    • Casel.Cul.DLL
    • castle.dynamicproxy2.dll(城堡.dynamicproxy2.dll)
    • iesi.collections.dll日志4net.dll
    • nhibernate.bytecode.castle.dll文件
    • NHiBNATE.DLL

    问题如下:当我执行从数据库中读取产品信息的ASP.NET应用程序时,会收到以下错误消息:

    Unable to load type 'NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle' during configuration of proxy factory class.
    Possible causes are:
    - The NHibernate.Bytecode provider assembly was not deployed.
    - The typeName used to initialize the 'proxyfactory.factory_class' property of the session-factory section is not well formed.
    

    如果我将nhibernate.bytecode.castle.dll的本地副本放入ASP.NET应用程序的bin文件夹中,那么错误就消失了。但是一个新的错误出现了。它表示nhibernate无法在businesslogic.dll中找到类(例如product等)。

    如果我将businesslogic.dll的本地副本放入ASP.NET应用程序的bin文件夹中,即使这个错误被修复,应用程序也会运行良好。

    但是,这是不需要的,因为我不想在每次更新业务逻辑时使用业务逻辑重新编译每个应用程序。

    我发现这篇文章承诺会有所帮助: http://markmail.org/message/o22r2x5fng7i6jn5#query:activerecord%20gac+page:1+mid:4rlqoicqyxjh3ypb+state:results

    不幸的是,这并不能解决问题。

    我将以下内容放入machine.config文件:

    <runtime>
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <qualifyAssembly partialName="NHibernate.ByteCode.Castle" fullName="NHibernate.ByteCode.Castle,version=2.1.2.4000,publicKeyToken=aa95f207798dfdb4,culture=neutral" />
      </assemblyBinding>
    </runtime>
    

    错误仍然相同。nhibernate找不到nhibernate.bytecode.castle.proxyfactoryFactory类

    任何帮助都非常感谢。

    2 回复  |  直到 14 年前
        1
  •  3
  •   Community CDub    7 年前

    我在这里找到了解决方案: .NET assemblyBinding configuration ignored in machine.config

    问题是我试图从machine.config文件中重定向到GAC中的程序集。这似乎被忽略了。web.config文件中的以下两个条目起了作用:

    <runtime>
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <qualifyAssembly partialName="NHibernate.ByteCode.Castle" fullName="NHibernate.ByteCode.Castle,version=2.1.2.4000,publicKeyToken=aa95f207798dfdb4,culture=neutral" />
        <qualifyAssembly partialName="BusinessLogic" fullName="BusinessLogic,version=2.0.0.0,publicKeyToken=e1ee7b158bf26e98,culture=neutral"/>
      </assemblyBinding>
    </runtime>
    

    我必须使用我的业务逻辑将这些条目添加到每个应用程序的配置文件中。但现在它与GAC的集会合作。

        2
  •  0
  •   dmonlord    14 年前

    nhibernate.bytecode.*程序集是动态加载的(它们不作为标准程序集引用),nhibernate在应用程序目录中查找它们。 如果你想的话,你可以检查一下nhibernate源文件,以确定文件是如何找到的。

    您可以将类似的内容添加到Visual Studio中的后期生成事件中:

    xcopy $(SolutionDir)SharedLibs\Bytecode.dll $(ProjectDir)$(OutDir) /Y /C