質問

I'm configuring NHibernate on SharePoint 2010 web application. Previously it works fine when mappings and domain were in one project. But during refactoring process I splitted solution on several projects. I've also implemented my custom IHttpModule where I want to initialize nhibernate configuration

    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);
    }

And 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();
            }
        }
    }

And in BuildConfiguration() I have very strange error (InnerException): "Entry point was not found." Stack trace shows that getting mapping information is cause of error:

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()

All assemblies are in the GAC. I tried to copy them in _app_bin or bin but without success.

UPDATE

Please, help me! I'm stuck with this weird problem :(

役に立ちましたか?

解決

I found solution.

Take a look at my configuration lines:

config = new Configuration();
config = config.Configure(specifiedConfigurationFilePath);
config = Fluently.Configure(config)
                 .Mappings(m => m.FluentMappings.AddFromAssemblyOf<ItemMap>())
                 .BuildConfiguration();

I'm creating new nhibernate configuration object passing it to fluent-nhibernate static initializer method. This is a point where things happen. Fluent-nhibernate can't take configuration from specified file. Instead it can take nhibernate configuration object with file path specified which it then uses to build configuration. Previous version of my application was in one assembly and this way of configuration seems to work fine. But when I split up application the issue appeared. So to solve the problem I should to take nhibernate configuration info from web.config file. I can't merge settings of timer job and web-application in one file as I could in single-assembly project. So I had to have several configuration files and always use classic lines like that:

Fluently
 .Configure()
  .Mappings(p => p.FluentMappings
                   .AddFromAssemblyOf<ItemMap>())
                    .BuildConfiguration()

It's appear to be some sort of fluent-nhibernate bug or something...

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top