Configure NHibernate with mapping assembly dll in other dir than config file
First I will try to explain what I want to do.
The app loads a NhHibernate config file and parse the xml, allowing changes to the connection string and the mapping assembly.
The problem is that when I run the app in the directory that contains NHibernate.dll and all references, it works well, but if I run the app from other directory, the Configure() fails.
This is the code I have:
Configuration cfg = new Configuration();
cfg.Properties = props; // the properties are OK
cfg.AddAssembly(Assembly.LoadFrom(filename)); // <- this line fails
When I debugged NHibernate, it failed in this method in class NHibernate.Util.ReflectUtil:
public static System.Type TypeFromAssembly(AssemblyQualifiedTypeName name, bool throwOnError)
.
.
Assembly assembly = Assembly.Load(name.Assembly); // line 265
.
.
That method search for the assembly in the current domain, but the assembly is located in other directory.
The purpose of the app is to replicate in different development and test environments little changes made to the开发者_StackOverflow社区 entities. I don't want the others developers copy this app to their projects, I want that they select the correct project directory in the app, then the app will configure NHibernate, and if requested by the user, it will execute the updates to their DB.
I tried loading/executing the app in a different AppDomain but with no success.
Maybe this is not possible? or I'm missing something.
Some advise please, I'm stuck with this problem.PD: Sorry for my English, correct the question if necessary.
If the required assemblies are in a non-standard directory, you will need to help the CLR find them. There are a number of ways to do this:
- Via a probing element in configuration.
- Via
AppendPrivatePath
in a customAppDomain
. - Via the
AssemblyResolve
event of anyAppDomain
.
精彩评论