2014-05-22 116 views
1

我想用MemCache配置Fluent NHibernate,但出现以下错误。我使用MVC5 + CastleWindsor + FluentNHibernate + UOW用NHibernate.Caches.MemCached配置Fluent Nhibernate

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: Object reference not set to an instance of an object.] Memcached.ClientLibrary.SockIOPool.Initialize() in C:\devroot\memcacheddotnet\trunk\clientlib\src\clientlib\SockIOPool.cs:441 NHibernate.Caches.MemCache.MemCacheProvider.Start(IDictionary`2 properties) +3627
NHibernate.Impl.SessionFactoryImpl..ctor(Configuration cfg, IMapping mapping, Settings settings, EventListeners listeners) +1098
NHibernate.Cfg.Configuration.BuildSessionFactory() +181
FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory() +73

[FluentConfigurationException: An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.

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

在此先感谢

回答

0

它看起来与未初始化的服务器列表中的问题。

这是从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(); 

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

+0

谢谢你的回应。我觉得我错过了我的设置中的一大步。我没有看到SockIOPool.cs文件。所以我会找出我缺少的东西,我会在这里回复。再次感谢您的回复,请收藏本文:)我将很快提出一些问题:)谢谢。 – user3634311