NHibernate 无法从 GAC 加载程序集(NHibernate.ByteCode.Castle 和 BusinessLogic)

发布于 2024-09-16 15:34:00 字数 2070 浏览 7 评论 0原文

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

设置如下:

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

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

  • Antlr3.Runtime.dll BusinessLogic.dll
  • BusinessLogic.dll
  • Castle.ActiveRecord.dll
  • Castle.Components.Validator.dll
  • Castle.Core.dll
  • Castle.DynamicProxy2.dll
  • Iesi.Collections.dll log4net.dll
  • NHibernate.ByteCode.Castle.dll
  • NHibernate.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

非常感谢任何帮助。

I was lookin all over the internet for this particular problem of mine. I found some suggested solutions but they don't work.

Here is the setup:

I am using ActiveRecord/NHibernate. I created an assembly wrapping ActiveRecord called the BusinessLogic. The idea is that all my projects should use the BusinessLogic instead of referencing ActiveRecord/NHibernate directly.

I installed the following files in the GAC (Global Assembly Cache of .NET):

  • Antlr3.Runtime.dll BusinessLogic.dll
  • BusinessLogic.dll
  • Castle.ActiveRecord.dll
  • Castle.Components.Validator.dll
  • Castle.Core.dll
  • Castle.DynamicProxy2.dll
  • Iesi.Collections.dll log4net.dll
  • NHibernate.ByteCode.Castle.dll
  • NHibernate.dll

The Problem is the following: When I execute my ASP.NET application that reads product information from the database I get the following error message:

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.

If I put a local copy of NHibernate.ByteCode.Castle.dll into the bin folder of the ASP.NET application the error is gone. But a new error shows up. It says that NHibernate cannot find the classes within the BusinessLogic.dll (e.g. Product and so on).

If I put a local copy of BusinessLogic.dll into the bin folder of the ASP.NET application even this error is fixed and the application runs great.

This however is not desired, because I don't want to recompile every application using the BusinessLogic, whenever the BusinessLogic is updated.

I found this article that promised to be helpful: http://markmail.org/message/o22r2x5fng7i6jn5#query:activerecord%20gac+page:1+mid:4rlqoicqyxjh3ypb+state:results

Unfortunately this does not solve the problem.

I put the following into the machine.config file:

<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>

The error is still the same. NHibernate cannot find the class NHibernate.ByteCode.Castle.ProxyFactoryFactory

Any help is much appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

枉心 2024-09-23 15:34:00

我实际上在这里找到了解决方案: .NET assemblyBinding 配置在 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 议会合作。

I actually found the solution here: .NET assemblyBinding configuration ignored in machine.config

The Problem was that I was trying to redirect to an assembly in the GAC from within the machine.config file. It looks like that is ignored. The following two entries in the web.config file did the trick:

<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>

I will have to add these entries into the config file of every application using my Business Logic. But now it works with the assemblies of the GAC.

风情万种。 2024-09-23 15:34:00

Nhibernate.ByteCode.* 程序集是动态加载的(它们不作为标准程序集引用),并且 Nhibernate 在应用程序目录中查找它们。
如果您愿意,可以检查 NHibernate 源代码以准确确定如何找到这些文件。

您可以将类似的内容添加到 Visual Studio 中的构建后事件中:

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

Nhibernate.ByteCode.* assemblies are dynamically loaded (they're not referenced as standard assemblies) and Nhibernate looks for them in the application directory.
If you want you can chech NHibernate source to be exactly sure how the files are found.

You can add something like this to the post build event in visual studio:

xcopy $(SolutionDir)SharedLibs\Bytecode.dll $(ProjectDir)$(OutDir) /Y /C
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文