views:

35

answers:

1

This call

// this._cfg is an NHibernate Configuration instance
this._sessionFactory = this._cfg.BuildSessionFactory();

Gives me this exception at runtime (NOT at compile time).

Could not load file or assembly 'NHibernate.ByteCode.Castle' or one of its dependencies. The system cannot find the file specified.":"NHibernate.ByteCode.Castle

OK so far. But the thing is, this code is running in a class library project, and I have referenced NHibernate.ByteCode.Castle (along with all the other NHibernate dll's) in that project.

Wierder: I can fix the exception by additionally referencing the NHibernate dll's in the Windows WPF executable project that calls my class library. But the Windows WPF executable contains no code that directly uses NHibernate (as evidenced by: It compiles fine without any NHibernate references). So what's going on? Apparently it's insufficient to reference NHibernate.ByteCode.Castle in the project that actually uses the NHibernate stuff. Anyone know why?

+1  A: 

I wouldn't reference the castle byte code factory at all; just ensure it (and all other needed dependancies) are copied to the output directory using a post-build step.

DanP
Thanks Dan, I now understand. The app doesn't need to reference these dll's, but they do need to be present in the output directory (I guess, so that they can be accessed by somthing like reflection?) That explains the behaviour I was seeing. In the end I left them as refs in the project since that clutters the solution explorer less than adding them as separate items to the project output folder.
PhantomDrummer
@user409898: Correct, they are loaded dynamically at runtime..I would still recommend performing your assembly copying using a postbuild step though, keeps things far simpler. Just put all of your copy operations into a batch file and call that.
DanP