views:

32

answers:

2

Hi! I'm using Microsoft Visual Studio 2010. I start to work with FluentNHibernate 1.1. After configuration.BuildSessionFactory() execute, i have exception.

Message "Could not load file or assembly 'Castle.DynamicProxy2, Version=2.1.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc' or one of its dependencies.

Castle.DynamicProxy2 present in project references, version is correct. Also this assembly present in build path. I can't resolve this problem...

p.s. i try to get last version of FluentNHibernate, build and run with assembly in my project. I have the same error.

A: 

It may be because you target framework 4.0 and the Castle assembly is compiled for 2.0.

You can try to add this to your app.config, within the <configuration /> element, to allow mixed version at runtime:

<startup useLegacyV2RuntimeActivationPolicy="true">
  <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
Mael
A: 

You say the reference to Castle.DynamicProxy2 exists in your project, and is the correct version. Did you verify its filepath, whether it is correct?

There is a tiny problem with MSVS that is about reference paths. Once you reference an assembly, and your project gets compiled, a copy of this assembly is made to your output directory. Often, its reference path is changed automatically to point to this output directory. Then, if you clean up or something, your file no longer exists where it is expected, and causes this kind of error message.

To resolve this problem, you need to remove your reference the problematic assembly, and add it again as a reference to your project.

Another simple approach is to set your reference paths per project from within your project properties. Unfortunately, you will be required to set them per project, so as many times as the project count your solution has. Plus, every programmer of your team will do to do so as well, as these settings are kept on the local machine and are not deployed within the project settings like parameters, for instance.

Will Marcouiller