我在 SharePoint 2010 Web 应用程序上配置 NHibernate。以前,当映射和域在一个项目中时,它可以正常工作。但是在重构过程中,我将解决方案拆分为几个项目。我还实现了我想要初始化休眠配置的自定义 IHttpModule
protected void context_BeginRequest(object sender, EventArgs e)
{
var httpApplication = sender as HttpApplication;
lock (httpApplication )
{
if (!httpApplication.Context.Items.Contains(ApplicationConstants.IsApplicationInitialized))
{
httpApplication.Context.Items.Add(ApplicationConstants.IsApplicationInitialized, true);
InitInRequest(httpApplication);
}
}
httpApplication.Context.Items.Add(ApplicationConstants.SESSION, NhibernateManager.GetSession());
}
private void InitInRequest(HttpApplication httpApplication)
{
NhibernateManager.Init(ApplicationVariables.ApplicationSettingsPath);
}
和 NHibernateManager.Init():
public static void Init(string configurationFilePath)
{
specifiedConfigurationFilePath = configurationFilePath;
Configure();
InitSessionFactory();
}
private static void Configure()
{
if (config == null)
{
if (string.IsNullOrEmpty(specifiedConfigurationFilePath) == false)
{
config = new Configuration();
config = config.Configure(specifiedConfigurationFilePath);
config = Fluently.Configure(config)
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<ItemMap>())
.BuildConfiguration();
}
else
{
config = Fluently.Configure()
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<ItemMap>())
.BuildConfiguration();
}
}
}
在 BuildConfiguration() 中我有一个非常奇怪的错误(InnerException):“找不到入口点。” 堆栈跟踪显示获取映射信息是错误的原因:
at System.Collections.Generic.IDictionary`2.TryGetValue(TKey key, TValue& value)
at NHibernate.Cfg.Configuration.GetClassMapping(String entityName)
at NHibernate.Cfg.Configuration.GetClassMapping(Type persistentClass)
at FluentNHibernate.PersistenceModel.Configure(Configuration cfg)
at FluentNHibernate.Cfg.MappingConfiguration.Apply(Configuration cfg)
at FluentNHibernate.Cfg.FluentConfiguration.BuildConfiguration()
所有程序集都在 GAC 中。我试图将它们复制到 _app_bin 或 bin 但没有成功。
更新
请帮我!我被这个奇怪的问题困住了:(