Matt Braunwart
Matt Braunwart

Reputation:

A session factory has already been configured with the key of nhibernate.current_session

NOTE: I posted this on sharp architecture google groups also.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: SharpArch.Core.PreconditionException: A session factory has already been configured with the key of nhibernate.current_session

Source Error:

Line 49: base.Init(); Line 50: Line 51: NHibernateSession.Init(new WebSessionStorage (this), Line 52: new string[] { Server.MapPath("~/bin/ GCBA.Data.dll") }); Line 53: }

Source File: C:\Users\Matt\Desktop\Matt\GCBA\GCBA\GCBA.Web \Global.asax.cs Line: 51

Stack Trace:

[PreconditionException: A session factory has already been configured with the key of nhibernate.current_session]

SharpArch.Core.Check.Require(Boolean assertion, String message) in C:\MyStuff\Projects\SharpArchitecture\src\SharpArch\SharpArch.Core \DesignByContract.cs:62

SharpArch.Data.NHibernate.NHibernateSession.Init(ISessionStorage storage, String[] mappingAssemblies, AutoPersistenceModel autoPersistenceModel, String cfgFile, IDictionary`2 cfgProperties, String validatorCfgFile, IPersistenceConfigurer persistenceConfigurer) in C:\MyStuff\Projects\SharpArchitecture\src\SharpArch\SharpArch.Data \NHibernate\NHibernateSession.cs:70

SharpArch.Data.NHibernate.NHibernateSession.Init(ISessionStorage storage, String[] mappingAssemblies) in C:\MyStuff\Projects \SharpArchitecture\src\SharpArch\SharpArch.Data\NHibernate \NHibernateSession.cs:26

GCBA.Web.MvcApplication.Init() in C:\Users\Matt\Desktop\Matt\GCBA \GCBA\GCBA.Web\Global.asax.cs:51

System.Web.HttpApplication.InitInternal(HttpContext context, HttpApplicationState state, MethodInfo[] handlers) +335


This is the error I get trying to run from IIS7... I can run fine it seems out of VS2008 Cassini.... So I'm not certain what the issue is, I have the 7/16/2009 trunk build of S#arp and MVC.Net 1.0. The piece of code it is failing on is in the global.asax.cs Init() method. I really am pretty frustrated with this issue, because I have only found one other post concerning this, and it was in test cases, where as mine is actually trying to run the website from iis7 and all my tests pass fine.

If anyone has any idea what may be causing this issue, that would be great, thank you.

Upvotes: 3

Views: 2345

Answers (3)

Chris Haines
Chris Haines

Reputation: 6535

Probably a threading issue?

Have you tried something like this in your app initialisation:

private static bool haveInit
if (!haveInit)
{
    lock (@lock)
    {
        if (!haveInit))
        {
            NHibernateSession.Init(...);
            haveInit = true;
        }
    }
}

Upvotes: 0

Simon Söderman
Simon Söderman

Reputation: 335

I recently had the same problem. I used S#arp arch but used a normal asp.net website project (integrated in a cms). The whole problem for me was that Global.asax does not trigger on unknown filetypes or virtual urls. I solved it by writing my own HttpModule and loading it separately, this has the side-effect that NHibernate is initiated even though someone is only fetching an image. but for me it wasn´t an issue.

Hopefully that puts you in the right direction...

Upvotes: 1

LordHits
LordHits

Reputation: 5073

This sounds like IIS7 is not configured properly for ASP.NET MVC. See if this post on SO helps you in setting up IIS7 with ASP.NET MVC. I'm also using SharpArchitecture and after having IIS7 run in "integrated" mode, solved a bunch of issues.

Upvotes: 0

Related Questions