views:

41

answers:

2

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.

A: 

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
dmonlord
Do you mean like Assembly.Load(...)?If so it should be possible to use the qualifyAssembly attribute: http://msdn.microsoft.com/en-us/library/cd71chf0.aspxThe MSDN article mentions that:The partialName must match the name specified in your call. For example, you cannot specify "math" as the partialName attribute in your configuration file and call Assembly.Load("math, Version=3.3.3.3") in your code.It could be that the NHibernate.ByteCode.Castle assembly is loaded using the version, public key, culture code or a specific combination of these. But which one?
Krisztian Baller
Well the name used in the load is probably the one defined in the XML config file. Edit: Yes it is, see my own answer below.
Krisztian Baller
A: 

I actually found the solution here: http://stackoverflow.com/questions/198668/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.

Krisztian Baller