Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Nhibernate 创建SessionFactory时使用了无效或不完整的配置_Nhibernate_Fluent Nhibernate - Fatal编程技术网

Nhibernate 创建SessionFactory时使用了无效或不完整的配置

Nhibernate 创建SessionFactory时使用了无效或不完整的配置,nhibernate,fluent-nhibernate,Nhibernate,Fluent Nhibernate,下面是结尾的内部例外: 无法加载文件或程序集“ByteCode.Castle”或其依赖项之一。系统找不到指定的文件 我正在添加nhibernate的所有引用,使用的所有构建都是我的代码: 使用NHibernate; 使用氟纤维酸盐; 使用NHibernate.Cfg; 运用系统反思; 使用FluentNHibernate.Cfg.Db; 使用FluentNHibernate.Cfg; 使用NHibernate.ByteCode.Castle; 使用Castle.Core; 使用Castle.Dy

下面是结尾的内部例外:

无法加载文件或程序集“ByteCode.Castle”或其依赖项之一。系统找不到指定的文件

我正在添加nhibernate的所有引用,使用的所有构建都是我的代码:

使用NHibernate; 使用氟纤维酸盐; 使用NHibernate.Cfg; 运用系统反思; 使用FluentNHibernate.Cfg.Db; 使用FluentNHibernate.Cfg; 使用NHibernate.ByteCode.Castle; 使用Castle.Core; 使用Castle.DynamicProxy

名称空间 { 公共静态类NHibernateHelper { 私有静态无效字节码() { //只是为了确保字节码广播已加载 ProxyFactory fake=新的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
}
#地区会议
私人静态ISessionFactory_sessionFactory;
私有静态ISessionFactory会话工厂
{
得到
{
if(_sessionFactory==null)
{
引用字节码();
var配置=新配置();
#亚硝酸根区域
IPersistenceConfigurer persistenceConfigurer=MsSqlConfiguration.MsSql2008.ConnectionString(“数据源=;初始目录=3abash;集成安全性=True”).ShowSql().ProxyFactoryFactory(“ByteCode.Castle.proxyFactory,ByteCode.Castle”);
//
//使用持久性配置器属性初始化nhibernate
//Configuration cfg=persistenceConfigurer.ConfigureProperties(新配置());
//var persistenceModel=新persistenceModel();
//persistenceModel.AddMappingsFromAssembly(Assembly.Load(“3adash.Mappings”);
//persistenceModel.Configure(cfg);
尝试
{
_sessionFactory=Fluently.Configure().Database(persistenceConfigurer).Mappings(m=>m.FluentMappings.AddFromAssembly(Assembly.Load(“3adash.Mappings”))).BuildSessionFactory();
}
catch(System.Exception-ex)
{
掷骰子;
}
//cfg.SetProperty(
//将映射定义添加到nhibernate配置
//试一试
//{
//var persistenceModel=新persistenceModel();
//persistenceModel.AddMappingsFromAssembly(Assembly.Load(“3adash.Mappings”);
//persistenceModel.Configure(cfg);
//_sessionFactory=configuration.BuildSessionFactory();
//}
//catch(System.Exception-ex)
//{
//掷骰子;
//}
#端区
}
返回工厂;
}
}
公共静态会话OpenSession()
{
返回SessionFactory.OpenSession();
}
#端区
#区域积垢作业
公共静态void Add(T newObject)
{
使用(ISession session=NHibernateHelper.OpenSession())
{
使用(ITransaction transaction=session.BeginTransaction())
{
session.Save(newObject);
Commit();
}
}
}
公共静态无效更新(T UpdateObject)
{
使用(ISession session=NHibernateHelper.OpenSession())
{
使用(ITransaction transaction=session.BeginTransaction())
{
会话更新(updateObject);
Commit();
}
}
}
公共静态无效删除(T deletedObject)
{
使用(ISession session=NHibernateHelper.OpenSession())
{
使用(ITransaction transaction=session.BeginTransaction())
{
删除(删除对象);
Commit();
}
}
}
公共静态T GetById(int objectID)
{
使用(ISession session=NHibernateHelper.OpenSession())
{
使用(ITransaction transaction=session.BeginTransaction())
{
返回会话.Get(objectID);
}
}
}
#端区
}
}

    #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
}

到目前为止,我无法测试任何东西,我真的对这个错误感到厌烦了,我向我所有的类库添加了nhibernate引用,但没有任何东西得到修复,有人能帮忙吗???

确保您有对nhibernate.ByteCode.Castle.dll和Castle.Core.dll的程序集引用(如果您使用NH2.1.2,还有Castle.dynamicProxy.dll)*确保将其复制到输出目录。您使用的是哪个版本的Fluent NHibernate和NHibernate


*Castle.DynamicProxy 2.dll已与Castle.Core.dll合并。NH3中使用了Castle.Core.dll的较新合并版本。

是的,这正是James所说的。由于代理工厂仅在NHibernate的配置中指定,而解决方案中的任何类库均未实际使用,因此它(始终)不会使用在生成时复制到应用程序项目

对我来说,有效的方法是只引用所有类库中的最小值,然后直接引用应用程序项目中所有额外的位和块。当我尝试运行应用程序项目时,应用程序项目会告诉我它缺少什么。比如代理工厂(NHibernate.ByteCode.Castle、Castle.Core和Castle.DynamicProxy)二级缓存(NHibernate.Caches.SysCache)和HQL解析(Antlr3.Runtime)等。每次投诉后,只需将它们作为引用添加到应用程序项目中即可

编辑

在您发布的错误中,它抱怨找不到“ByteCode.Castle”。所讨论的程序集实际上是“NHibernate.ByteCode.Castle”。错误可能在您定义代理工厂的App.config或Web.config中。键入了吗