title: Fluent NHibernate Solution Structure - How to reference DLL's once in back end of Web App / Console App
body: <p>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.  </p>
  
  <p>My Solution structure is as follows:</p>
  
  <p><strong>BackEnd</strong> -- Class Library -- Business logic and Data Repositories &amp; public API.. this level uses NHibernate privately for data storage and does not expose any NHibernate classes to the front end</p>
  
  <p><strong>Public</strong> --  Class Library --- POCO Objects with no dependencies used by both front end and back end. Backend uses NHibernate to persist these objects.  </p>
  
  <p><strong>Front End</strong> -- Console App &amp; a MVC Web App -- (Two front end apps (1) MVC2 Web app &amp;&amp; (2) a console app) reference the Public &amp; Back End projects and just use a few public methods on to interact with the Back End using Public objects.</p>
  
  <p>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: </p>
  
  <pre><code>   public static ISessionFactory CreateSessionFactory()
      {
          return Fluently.Configure()
           .Database(SQLiteConfiguration.Standard.UsingFile(DbFile))
           .Mappings(m =&gt; m.AutoMappings
                 .Add(AutoMap.AssemblyOf&lt;EngineInfo&gt;(type =&gt; 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. 
  
  
      }
  </code></pre>
  
  <p>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.   </p>
  
  <p>If I do reference Nhibernate's dlls everything runs fine but in my front end apps I get the following warning at compile time:</p>
  
  <p>*</p>
  
  <blockquote>
    <p>Found conflicts between different
    versions of the same dependent
    assembly.</p>
  </blockquote>
  
  <p>*</p>
  
  <p>Any suggestions?</p>
  
  <p>--Update--</p>
  
  <p>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. </p>
  
  <p>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.</p>
  
  <p>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:</p>
  
  <p>Do you want to fix these conflicts by adding binding redirect records to the appconfig file?  --- MSDN on the option -- <a href="http://msdn.microsoft.com/en-us/library/bb383993.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/bb383993.aspx</a></p>
  
  <p>Any advice?</p>
  
  <p><strong>---Update---</strong>
  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?</p>