【问题标题】:Configure Fluent Nhibernate with NHibernate.Caches.MemCached使用 NHibernate.Caches.MemCached 配置 Fluent Nhibernate
【发布时间】:2023-04-11 09:16:02
【问题描述】:

我正在尝试使用 MemCache 配置 Fluent NHibernate,但出现以下错误。我正在使用 MVC5+CastleWindsor+FluentNHibernate+UOW

private static ISessionFactory CreateNhSessionFactory() { var connStr = System.Configuration.ConfigurationManager.ConnectionStrings["AESConnect"].ConnectionString; return Fluently.Configure() .Database(MsSqlConfiguration.MsSql2008.ConnectionString(connStr)) .Cache(c=>c.ProviderClass(typeof(NHibernate.Caches.MemCache.MemCacheProvider).AssemblyQualifiedName).UseSecondLevelCache()) .ExposeConfiguration(e=>e.SetProperty("hibernate.cache.use_second_level_cache","true")) .Mappings(m => m.FluentMappings.AddFromAssembly(Assembly.GetAssembly(typeof(HotelsMap)))) .BuildSessionFactory(); }

错误:

[NullReferenceException: 对象引用未设置为 对象。] Memcached.ClientLibrary.SockIOPool.Initialize() 在 C:\devroot\memcacheddotnet\trunk\clientlib\src\clientlib\SockIOPool.cs:441 NHibernate.Caches.MemCache.MemCacheProvider.Start(IDictionary`2 属性)+3627
NHibernate.Impl.SessionFactoryImpl..ctor(配置 cfg,IMapping 映射、设置设置、EventListeners 侦听器)+1098
NHibernate.Cfg.Configuration.BuildSessionFactory() +181
FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory() +73

[FluentConfigurationException:无效或不完整的配置 在创建 SessionFactory 时使用。检查潜在原因 集合和 InnerException 了解更多详细信息。

] FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory() +117 AESRepositories.Installers.AESInstaller.CreateNhSessionFactory() ....

提前致谢

【问题讨论】:

    标签: configuration fluent-nhibernate memcached castle-windsor


    【解决方案1】:

    似乎是服务器列表未初始化的问题。

    这是来自 SockIOPool.cs 文件:

    /// The pool must be initialized prior to use. This should typically be early on
    /// in the lifecycle of the application instance.
    

    同一个文件有一个这样的初始化示例:

    /// String[] serverlist = {"cache0.server.com:12345", "cache1.server.com:12345"};
    ///
    /// SockIOPool pool = SockIOPool.GetInstance();
    /// pool.SetServers(serverlist);
    /// pool.Initialize();  
    

    也许你缺少连接池的配置,或者你没有初始化它。

    【讨论】:

    • 感谢您的回复。我觉得我在我的设置中错过了一大步。我没有看到 SockIOPool.cs 文件。所以我要找出我错过了什么,我会在这里回复。再次感谢您的回复,请将此帖子添加为书签 :) 我很快就会有一些问题 :) 谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多