Invalid or incomplete configuration used to create SessionFactory

and here is the internal exception at the end:

Failed to load file or assembly "ByteCode.Castle" or one of its dependencies. The system cannot find the specified file.

I add all the links for nhibernate, all assemblies are used here: my code:

using NHibernate; Using FluentNHibernate using NHibernate.Cfg; using System.Reflection; using FluentNHibernate.Cfg.Db; using FluentNHibernate.Cfg; using NHibernate.ByteCode.Castle; using Castle.Core; using Castle.DynamicProxy;

namespace _3adaseh {public static class NHibernateHelper {private static void ReferByteCode () {// Just to make sure ByteCodeCastle is loaded ProxyFactory fake = new ProxyFactory (); }

    #region Session
    private static ISessionFactory _sessionFactory;

    private static ISessionFactory SessionFactory
    {
        get
        {
            if (_sessionFactory == null)
            {
                ReferByteCode();
                var configuration = new Configuration();
                #region Configuring Fluent NHibernate
                IPersistenceConfigurer persistenceConfigurer = MsSqlConfiguration.MsSql2008.ConnectionString("Data Source=.;Initial Catalog=3adaseh;Integrated Security=True").ShowSql().ProxyFactoryFactory("ByteCode.Castle.ProxyFactoryFactory, ByteCode.Castle");
                //
                // initialize nhibernate with persistance configurer properties 
                //Configuration cfg = persistenceConfigurer.ConfigureProperties(new Configuration());
                //var persistenceModel = new PersistenceModel();
                //persistenceModel.AddMappingsFromAssembly(Assembly.Load("3adaseh.Mappings"));
                //persistenceModel.Configure(cfg);
                try
                {
                    _sessionFactory = Fluently.Configure().Database(persistenceConfigurer).Mappings(m => m.FluentMappings.AddFromAssembly(Assembly.Load("3adaseh.Mappings"))).BuildSessionFactory();
                }
                catch (System.Exception ex)
                {
                    throw ex;
                }

                //cfg.SetProperty(
                // add mappings definition to nhibernate configuration 
                //try
                //{
                //    var persistenceModel = new PersistenceModel();
                //    persistenceModel.AddMappingsFromAssembly(Assembly.Load("3adaseh.Mappings"));
                //    persistenceModel.Configure(cfg);
                //    _sessionFactory = configuration.BuildSessionFactory();
                //}
                //catch (System.Exception ex)
                //{
                //    throw ex;
                //}
                  #endregion




            }
            return _sessionFactory;
        }
    }

    public static ISession OpenSession()
    {
        return SessionFactory.OpenSession();
    }
    #endregion

    #region CRUD Operations
    public static void Add<T>(T newObject)
    {
        using (ISession session = NHibernateHelper.OpenSession())
        {
            using (ITransaction transaction = session.BeginTransaction())
            {
                session.Save(newObject);
                transaction.Commit();
            }
        }
    }


    public static void Update<T>(T updatedObject)
    {
        using (ISession session = NHibernateHelper.OpenSession())
        {
            using (ITransaction transaction = session.BeginTransaction())
            {
                session.Update(updatedObject);
                transaction.Commit();
            }
        }
    }

    public static void Remove<T>(T deletedObject)
    {
        using (ISession session = NHibernateHelper.OpenSession())
        {
            using (ITransaction transaction = session.BeginTransaction())
            {
                session.Delete(deletedObject);
                transaction.Commit();
            }
        }
    }

    public static T GetById<T>(int objectID)
    {
        using (ISession session = NHibernateHelper.OpenSession())
        {
            using (ITransaction transaction = session.BeginTransaction())
            {
                return session.Get<T>(objectID);
            }
        }
    }
    #endregion
}

}

I couldn’t check anything so far, I am really bored with this error, I added nhibernate links to all my class libraries and nothing is fixed, can anyone help please

+5
source share
3 answers

, NHibernate.ByteCode.Castle.dll Castle.Core.dll( Castle.DynamicProxy2.dll, NH2.1.2) *, , . Fluent NHibernate NHibernate ?

* Castle.DynamicProxy2.dll Castle.Core.dll. NH3 Castle.Core.dll.

+2

, , . factory NHibernate - , () .

, , . , , . , factory (NHibernate.ByteCode.Castle, Castle.Core Castle.DynamicProxy), (NHibernate.Caches.SysCache) HQL (Antlr3.Runtime) .. .

Edit

, "ByteCode.Castle". "NHibernate.ByteCode.Castle". App.config Web.config, factory. ?

<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
    <session-factory>
        ...
        <property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
        ...
    </session-factory>
</hibernate-configuration>
0

, ,

ProxyFactoryFactory ( "ByteCode.Castle.ProxyFactoryFactory, ByteCode.Castle" );

without the word nhibernate, since I read nhibernate 2.1, removed that word from the links, so it looked for bytecode.castle, and when I renamed this dll, it did missmatch, and I created a big mess myself, now I just deleted the name nhibernate and added links manually ..... and it works manually, thanks to everyone :)

0
source

All Articles