Fluent NHibernate - exception occurred during configuration

3.7k views Asked by At

I am using Fluent NHibernate with an external 'hibernate.cfg.xml' file. by machine name like this "Environment.MachineName + ".cfg.xml""

Following is the configuration code where I am getting error:

public static bool BuildSessionFactory()
        {
            if (_sessionFactory != null) return false;

        var configuration = new NHibernate.Cfg.Configuration();
        configuration.Configure(Environment.MachineName + ".cfg.xml");
        configuration.AddAssembly(System.Reflection.Assembly.GetExecutingAssembly());

        _sessionFactory = Fluently.Configure(configuration)
              .Mappings(m => m.FluentMappings.AddFromAssemblyOf<NHibernateHelper>())
              .BuildSessionFactory();

        return true;
    }

But When NHibernate is trying to configure, I am getting floowing error:

exception says:

FluentNHibernate.Cfg.FluentConfigurationException was unhandled
Message: An unhandled exception of type 'FluentNHibernate.Cfg.FluentConfigurationException' occurred in FluentNHibernate.dll
Additional information: An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.
1

There are 1 answers

2
amcdermott On BEST ANSWER

This happens when there is a problem with your mapping. The main exception doesn't tell you much more than that.

You need to dig down to look at the text of the inner exceptions, then it is should typically become very clear what the problem is.

Edit: Just to add, although there is nothing wrong with it, in my opinion calling your configuration file <MachineName>.cfg.xml adds unnecessary complexity to your build and deploy process. You won't be able to deploy your code to another machine (Test or Product instances for example) without renaming the config file.