开发者

NHibernate unable to load assemblies (NHibernate.ByteCode.Castle and BusinessLogic) from GAC

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 开发者_如何学Pythonthat 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.


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.


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜