I'm organizing a VisualStudio 2008 solution using Fluent NHibernate and I would like to keep all the NHibernate dll dependencies buried in a "Back End" class library and let the front end Web app or Console app be ignorant of NHibernate.
My Solution structure is as follows:
BackEnd -- Class Library -- Business logic and Data Repositories & public API.. this level uses NHibernate privately for data storage and does not expose any NHibernate classes to the front end
Public -- Class Library --- POCO Objects with no dependencies used by both front end and back end. Backend uses NHibernate to persist these objects.
Front End -- Console App & a MVC Web App -- (Two front end apps (1) MVC2 Web app && (2) a console app) reference the Public & Back End projects and just use a few public methods on to interact with the Back End using Public objects.
What I would like to do is only reference NHibernate and its many dependencies once in Back End and have the Front End apps just reference the back end project. However, the Fluent BackEnd crashes at runtime if I don't reference every one of Nhibernate's dependencies in my front end app in addition to referencing them in the Back End. Here's the Back End code it crashes on complaining it can't find the nhibernate dlls when the front end omits the reference:
public static ISessionFactory CreateSessionFactory()
{
return Fluently.Configure()
.Database(SQLiteConfiguration.Standard.UsingFile(DbFile))
.Mappings(m => m.AutoMappings
.Add(AutoMap.AssemblyOf<EngineInfo>(type => type.Namespace.Contains("BackEnd"))
.Conventions.Add(DefaultCascade.All())
.Conventions.Add(DefaultLazy.Never())
)
) //emd mappings
.ExposeConfiguration(BuildSchema)//Delete and remake a fresh tmp db
.BuildSessionFactory();//finalizes the whole thing to send back.
}
It may be that I've accidentally exposed a NHibernate dependent resource to the Front End apps but I don't get any compile time errors, and I'd love a little direction.
If I do reference Nhibernate's dlls everything runs fine but in my front end apps I get the following warning at compile time:
*
Found conflicts between different versions of the same dependent assembly.
*
Any suggestions?
--Update--
I've narrowed the dlls that I have to reference in the front end down to NHibernate.ByteCode.Castle.dll and System.Data.SQLite I can skip all the others and not get runtime errors.. at least none yet.
I'm still not sure why either would be required because the front end never uses any NH or SQL lite resources except through the public interface of the back end which doesn't offer any Nhibernate or SQLite resources. All classes that touch NHibernate or SQLite are marked Internal so I'm not sure what could cause this dependency.
The visual studio dependency warning offers a solution that I'm a bit hesitant to apply since I don't know why the problem came up in the first place:
Do you want to fix these conflicts by adding binding redirect records to the appconfig file? --- MSDN on the option -- http://msdn.microsoft.com/en-us/library/bb383993.aspx
Any advice?
---Update--- Tom below seems to have replicated my problem so this is starting to sound like a NHibernate dll bug. I also tried upgrading from VS 2008 to 2010 and rebuilt the whole solution and replicated the error there. Any one want to take a look to make sure we're not missing something before I try to report it?