开发者

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:

  1. Via a probing element in configuration.
  2. Via AppendPrivatePath in a custom AppDomain.
  3. Via the AssemblyResolve event of any AppDomain.
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜