Question

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.

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.

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).

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!

DLL Versions:

  • NHibernate - 3.3.1.4000
  • FluentNHibernate - 1.3.0.733
  • Fitnesse - v20111026
  • fitSharp - 2.2.4498.25493

Here is my entity:

// 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; }
}

my mapping file:

// namespace Reporting.Infrastructure
public sealed class HoldingsMap : ClassMap<Holdings>
{
    public HoldingsMap()
    {
        Id(x => x.HoldingsId).GeneratedBy.Identity();
        Map(x => x.AsOfDate).Not.Nullable();
        Map(x => x.Portfolio).Not.Nullable();

        // adding these lines eventually leads to the error
        Component(x=> x.PriorPeriod).ColumnPrefix("Prior");
        Component(x=> x.CurrentPeriod).ColumnPrefix("Current");
    }
}

my SessionFactory (the error happens when BuildSessionFactory is called):

// namespace Reporting.Infrastructure
public class SessionFactory
{
    public ISessionFactory CreateSession(Action<Configuration> configurationFunction)
    {
        return CreateConfiguration().ExposeConfiguration(c => {}).BuildSessionFactory();
    }

    private FluentConfiguration CreateConfiguration()
    {
        var connectionString = "...";
        var msSqlConfiguration = MsSqlConfiguration.MsSql2008.ConnectionString(connectionString);
        var database = Fluently.Configure().Database(msSqlConfiguration);
        return database.Mappings(m => m.FluentMappings.AddFromAssemblyOf<SessionFactory>().Conventions.Add(ForeignKey.EndsWith("Id")));
    }
}

I get this stack trace:

__EXCEPTION__:System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> FluentNHibernate.Cfg.FluentConfigurationException: An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.

 ---> FluentNHibernate.Cfg.FluentConfigurationException: An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.

 ---> 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)

FWIW, this is how I use the session factory from my Fitnesse Tests project:

// namespace Reporting.FitnesseTests
public class Database
{
    public static ISession Session { get; private set; }

    public static void Setup()
    {
        Session = new SessionFactory().CreateSession().OpenSession();
    }
}

and my Fitnesse Classpath is:

!path ..\Reporting.FitnesseTests\bin\Debug\Reporting.FitnesseTests.dll
Was it helpful?

Solution

Try putting the DLLs that the test is looking for in the same folder as the fitsharp Runner.exe. One problem that I ran into is that .NET run-time dependencies that are defined in app.config are resolved from the directory in which the process is executed from which in this case is probably the directory where fitsharp resides. There is a apparently a way to use the fitsharp suite configuration file to change this behavior but I haven't been able to get it working successfully (http://fitsharp.github.com/FitSharp/SuiteConfigurationFile.html).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top