title: Unable to find assembly FluentNHibernate when mapping Component while running Fitnesse test
body: <p>I have run into a very weird issue.  I have several working Fitnesse tests which insert data in a database, then test my full MVC application stack.</p>
  
  <p>When I try to add 2 Component property mappings to my entity map, I get an error saying "Unable to find assembly 'FluentNHibernate ...' which seems somewhat cryptic.</p>
  
  <p>All of this is being run through Fitnesse, so this could be an issue with how Fitnesse loads dependencies... I have no idea of knowing for sure though.  The only thing I know is that this code runs fine until I add the 2 "Component" mappings.  On top of that, those mappings run fine when this code is run through the normal web application (so I know the "Component" mapping and SessionFactory class works outside of Tests project).</p>
  
  <p>Does anyone have any ideas why I would get the error message I'm getting?  Please let me know if there is any other code I need to post.  Any help is greatly appreciated!</p>
  
  <p>DLL Versions:</p>
  
  <ul>
  <li>NHibernate - <strong>3.3.1.4000</strong> </li>
  <li>FluentNHibernate - <strong>1.3.0.733</strong> </li>
  <li>Fitnesse - <strong>v20111026</strong></li>
  <li>fitSharp - <strong>2.2.4498.25493</strong></li>
  </ul>
  
  <p>Here is my entity:</p>
  
  <pre><code>// namespace Reporting.Domain
  public class Holdings
  {
      public virtual int HoldingsId { get; set; }
      public virtual DateTime AsOfDate { get; set; }
      public virtual string Portfolio { get; set; }
  
      // need to add these next 2 properties!
      public virtual Balances PriorPeriod { get; set; }
      public virtual Balances CurrentPeriod { get; set; }
  }
  </code></pre>
  
  <p>my mapping file:</p>
  
  <pre><code>// namespace Reporting.Infrastructure
  public sealed class HoldingsMap : ClassMap&lt;Holdings&gt;
  {
      public HoldingsMap()
      {
          Id(x =&gt; x.HoldingsId).GeneratedBy.Identity();
          Map(x =&gt; x.AsOfDate).Not.Nullable();
          Map(x =&gt; x.Portfolio).Not.Nullable();
  
          // adding these lines eventually leads to the error
          Component(x=&gt; x.PriorPeriod).ColumnPrefix("Prior");
          Component(x=&gt; x.CurrentPeriod).ColumnPrefix("Current");
      }
  }
  </code></pre>
  
  <p>my SessionFactory (<strong>the error happens when BuildSessionFactory is called</strong>):</p>
  
  <pre><code>// namespace Reporting.Infrastructure
  public class SessionFactory
  {
      public ISessionFactory CreateSession(Action&lt;Configuration&gt; configurationFunction)
      {
          return CreateConfiguration().ExposeConfiguration(c =&gt; {}).BuildSessionFactory();
      }
  
      private FluentConfiguration CreateConfiguration()
      {
          var connectionString = "...";
          var msSqlConfiguration = MsSqlConfiguration.MsSql2008.ConnectionString(connectionString);
          var database = Fluently.Configure().Database(msSqlConfiguration);
          return database.Mappings(m =&gt; m.FluentMappings.AddFromAssemblyOf&lt;SessionFactory&gt;().Conventions.Add(ForeignKey.EndsWith("Id")));
      }
  }
  </code></pre>
  
  <p>I get this stack trace:</p>
  
  <pre><code>__EXCEPTION__:System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---&gt; FluentNHibernate.Cfg.FluentConfigurationException: An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.
  
   ---&gt; FluentNHibernate.Cfg.FluentConfigurationException: An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.
  
   ---&gt; System.Runtime.Serialization.SerializationException: Unable to find assembly 'FluentNHibernate, Version=1.3.0.733, Culture=neutral, PublicKeyToken=8aa435e3cb308880'.
     at System.Runtime.Serialization.Formatters.Binary.BinaryAssemblyInfo.GetAssembly()
     at System.Runtime.Serialization.Formatters.Binary.ObjectReader.GetType(BinaryAssemblyInfo assemblyInfo, String name)
     at System.Runtime.Serialization.Formatters.Binary.ObjectMap..ctor(String objectName, String[] memberNames, BinaryTypeEnum[] binaryTypeEnumA, Object[] typeInformationA, Int32[] memberAssemIds, ObjectReader objectReader, Int32 objectId, BinaryAssemblyInfo assemblyInfo, SizedArray assemIdToAssemblyTable)
     at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWithMapTyped(BinaryObjectWithMapTyped record)
     at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run()
     at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
     at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
     at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, IMethodCallMessage methodCallMessage)
     at FluentNHibernate.Utils.Extensions.DeepClone[T](T obj)
     at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
     at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
     at FluentNHibernate.Visitors.ComponentReferenceResolutionVisitor.ProcessComponent(ReferenceComponentMapping mapping)
     at FluentNHibernate.MappingModel.ClassBased.ReferenceComponentMapping.AcceptVisitor(IMappingModelVisitor visitor)
     at FluentNHibernate.MappingModel.MappedMembers.AcceptVisitor(IMappingModelVisitor visitor)
     at FluentNHibernate.MappingModel.ClassBased.ClassMappingBase.AcceptVisitor(IMappingModelVisitor visitor)
     at FluentNHibernate.MappingModel.HibernateMapping.AcceptVisitor(IMappingModelVisitor visitor)
     at FluentNHibernate.Utils.CollectionExtensions.Each[T](IEnumerable`1 enumerable, Action`1 each)
     at FluentNHibernate.PersistenceModel.ApplyVisitors(IEnumerable`1 mappings)
     at FluentNHibernate.PersistenceModel.BuildMappings()
     at FluentNHibernate.PersistenceModel.Configure(Configuration cfg)
     at FluentNHibernate.Cfg.MappingConfiguration.Apply(Configuration cfg)
     at FluentNHibernate.Cfg.FluentConfiguration.BuildConfiguration()
     --- End of inner exception stack trace ---
     at FluentNHibernate.Cfg.FluentConfiguration.BuildConfiguration()
     at FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory()
     --- End of inner exception stack trace ---
     at FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory()
     at Reporting.Infrastructure.SessionFactory.CreateSession() in Reporting.Infrastructure\SessionFactory.cs:line 32
     at Reporting.FitnesseTests.Database.Setup() in Reporting.FitnesseTests\Database.cs:line 23
     --- End of inner exception stack trace ---
     at fitSharp.Machine.Model.TypedValue.ThrowExceptionIfNotValid()
     at fitSharp.Slim.Operators.ExecuteCall.ExecuteOperation(Tree`1 parameters)
     at fitSharp.Slim.Operators.InvokeInstructionBase.Invoke(TypedValue instance, MemberName memberName, Tree`1 parameters)
  </code></pre>
  
  <p>FWIW, this is how I use the session factory from my Fitnesse Tests project:</p>
  
  <pre><code>// namespace Reporting.FitnesseTests
  public class Database
  {
      public static ISession Session { get; private set; }
  
      public static void Setup()
      {
          Session = new SessionFactory().CreateSession().OpenSession();
      }
  }
  </code></pre>
  
  <p>and my Fitnesse Classpath is:</p>
  
  <pre><code>!path ..\Reporting.FitnesseTests\bin\Debug\Reporting.FitnesseTests.dll
  </code></pre>