Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fluent NHibernate - exception occurred during configuration of persistence layer

I am using Fluent NHibernate with an external 'hibernate.cfg.xml' file.

Following is the configuration code where I am getting error:

       var configuration = new Configuration();
       configuration.Configure();

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

        return _sessionFactory;

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

An exception occurred during configuration of persistence layer.

The inner exception says:

The ProxyFactoryFactory was not configured. Initialize 'proxyfactory.factory_class' property of the session-factory configuration section with one of the available NHibernate.ByteCode providers.

I googled and according to some solutions I found, I have made following changes:

  1. Add following dlls to my app bin:

    Castle.Core.dll, Castle.DynamicProxy2.dll, NHibernate.ByteCode.Castle.dll

  2. Added follwing property in hibernate.cfg.xml

    <property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>

But still I am getting the same exception.

like image 755
inutan Avatar asked Oct 27 '09 13:10

inutan


Video Answer


2 Answers

I had this error too. It fires when you don't copy the mapping file (hibernate.cfg.xml) to the build directory.

Solution:

  • In Solution explorer, right click on the mapping file (hibernate.cfg.xml), choose Properties, then make sure that Copy To Output Directory has Copy if newer selected).
like image 67
kkmct Avatar answered Sep 19 '22 16:09

kkmct


As Alex InTechno said, this might be the error in the definition of your Mapping files or in mapped entities. I experienced the same error, when I have forgot that all properties in mapped classes have to be defined as virtual.

public String Name {get;set;}
public virtual String Name { get; set; }
like image 30
hoonzis Avatar answered Sep 21 '22 16:09

hoonzis