I have a situation where I am creating an assembly dynamically using the 
Mono CSharp Compiler (http://www.mono-project.com/CSharp_Compiler). The 
dynamic class contains my POCOs as well as my class mappings using the 
mapping by code feature.

When I am using mapping by code to generate the mapping the following 
exception is thrown...

Could not load file or assembly 'eval-3' or one of its dependencies. The 
system cannot find the file specified

After downloading the NHibernate source, I found the cause of the 
problem....

In ReflectHelper.cs on line 283, the assembly is loaded using...

Assembly assembly = Assembly.Load(name.Assembly). The variable 
name.Assembly does contain the dynamic assembly however, it doesn't exist 
in the filesystem.

I can fix the problem by changing the code to this...

// See if the assembly is already loaded in the current appdomain.

var loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies();

  Assembly assembly = loadedAssemblies.FirstOrDefault(y => y.FullName.
StartsWith(name.Assembly));

  if(assembly == null)

{

// if the assembly is not already in the current AppDomain, try to load it 
from file.

assembly = Assembly.Load(name.Assembly); 

if (assembly == null)

{

 log.Warn("Could not load type " + name + ". Possible cause: incorrect 
assembly name specified.");

 return null;

}

}
Can anyone see a problem with this approach?

Is it possible to get this added to the trunk?

Thanks for your time!

Take care,

Leo

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/nhusers?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to