views:

58

answers:

1

I'm trying to fluently configure a SessionFactory to access an Oracle9i database, using ODP.Net, and I'm getting this MissingConstructorException. I've got the actual fluent mappings sorted out ok, but I'm not sure what else it is that I've done wrong.

Here is the exception:

BasicConnectionTests.AssertThatWeCanConnectToADatabase : 

FailedFluentNHibernate.MissingConstructorException: 'FluentNHibernate.Automapping.IAutoClasslike, FluentNHibernate, Version=1.1.0.685, Culture=neutral, PublicKeyToken=8aa435e3cb308880' is missing a parameterless constructor.
at FluentNHibernate.Utils.Extensions.InstantiateUsingParameterlessConstructor(Type type)
at FluentNHibernate.PersistenceModel.Add(Type type)
at FluentNHibernate.Utils.CollectionExtensions.Each<T>(IEnumerable`1 enumerable, Action`1 each)
at FluentNHibernate.PersistenceModel.AddMappingsFromSource(ITypeSource source)
at FluentNHibernate.Cfg.FluentMappingsContainer.Apply(Configuration cfg)
at FluentNHibernate.Cfg.MappingConfiguration.Apply(Configuration cfg)
at FluentNHibernate.Cfg.FluentConfiguration.BuildConfiguration() 
FluentNHibernate.Cfg.FluentConfigurationException: An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.


at FluentNHibernate.Cfg.FluentConfiguration.BuildConfiguration()
at FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory() 
FluentNHibernate.Cfg.FluentConfigurationException: An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.


at FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory()
at MyAwesomeApp.sessionFactories.Oracle9SessionFactoryWrapper.Configure(String userName, String passWord, String dataBase) in Oracle9SessionFactoryWrapper.cs: line 26
at MyAwesomeApp.Tests.oracle.BasicConnectionTests.AssertThatWeCanConnectToADatabase() in BasicConnectionTests.cs: line 17

Here is the fluent mapping:

public ISessionFactory Configure(string userName, string passWord, string dataBase)
        {
            var config = Fluently.Configure();

            config.Database(
                OracleDataClientConfiguration.Oracle9
                    .ConnectionString(cs => cs.Username(userName).Password(passWord).Instance(dataBase))
                    .Driver("NHibernate.Driver.OracleDataClientDriver")
#if DEBUG
                    .ShowSql()
#endif
                );

            config.Mappings(
                m => m.FluentMappings.AddFromAssembly(Assembly.GetCallingAssembly()));

            return config.BuildSessionFactory();
        }

If anyone can point out where I'm going wrong, I'd be most grateful.

A: 

As James Gregory pointed in his comment on my question, I was doing something really stupid when informing Fluent were my mappings were.

When the code was exercised from the context of a unit test, m => m.FluentMappings.AddFromAssembly(Assembly.GetCallingAssembly()) tried to tell Fluent to look in the unit test assembly for the mappings - which is going to fail, miserably.

The answer is to use m => m.FluentMappings.AddFromAssemblyOf<Foo>(), where Foo is a type in the assembly were the mappings are.

sgrassie