-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: How to load mapping files from an assembly
PostPosted: Fri Jul 21, 2006 10:02 am 
Beginner
Beginner

Joined: Tue May 30, 2006 10:55 am
Posts: 21
Hibernate version: 1.0.2

How do I load the mapping files from an assembly which is not located in a subdirectory of the application instead of directly in the application directory?

At the moment I get always an error:

NHibernate.MappingException: persistent class myNamespace.myClass, myAssembly not found ---> System.TypeLoadException: Could not load type 'myNamespace.myClass, myNamespace.myClass', check that type and assembly names are correct

What I do is the following:
Code:
cfg = new Configuration();
log.Info("Extract configuring file from " + Assembly.GetExecutingAssembly());

cfg.Configure(Assembly.GetExecutingAssembly(), "myNamespace.Hibernate-JetDb.cfg.xml");
               
log.Info("Extract mapping files from " + Assembly.GetExecutingAssembly());

cfg.AddAssembly(Assembly.GetExecutingAssembly(), true);

log.Info("Build session factory.");
factory = cfg.BuildSessionFactory();


The configuration will be read in without any problems. The mapping file will be read in too. But the persistent class can not be found.
It is a really big problem for me because I can not change the directory structure and have to place the related dll into a subdirectory instead of the application directory.
For test purposes I put the assembly in the main directory an it seems to work.
[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 24, 2006 8:37 am 
Beginner
Beginner

Joined: Tue May 30, 2006 10:55 am
Posts: 21
It is really hard for me to believe that noone knows a possiblity to let NHibernate looking in a subdirectory for an assembly. Does really noone know it?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 24, 2006 10:06 am 
Newbie

Joined: Mon Jul 24, 2006 10:04 am
Posts: 1
Try to add this section to .config file of your application (app.config or web.config)

<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="YourSubDir"/>
</assemblyBinding>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 27, 2006 9:51 am 
Beginner
Beginner

Joined: Tue May 30, 2006 10:55 am
Posts: 21
I really get trouble with this. I think the hint with the config file is right, but it is not possible for me to get it working.

But the basic question is why nhibernate do not found the assembly. I call the AddAssembly method with the related assembly as parameter so I do not understand why this parameter will be discard and the load process starts with reflection and a location search of the assembly. Probably a bug?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 27, 2006 10:26 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
AddAssembly only searches through the assembly to find embedded mapping files. These mapping files contain class names which NHibernate tries to resolve using .NET reflection (i.e. Type.GetType or Assembly.Load plus Assembly.GetType). At this latter stage NHibernate doesn't know that the assembly it used to load mapping files from also contains the classes, so the problem occurs.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.