Using S#arp Architecture 2.3 RC, I am trying to publish two websites which use -mostly- the same codebase. The first of the applications I publish runs correctly, however, upon deploying and trying to run the second application, I get the following exception:
Access to the path 'C:\Windows\TEMP\nhibernate.current_session--851346262.bin' is denied.
When I refresh the window, I then get this exception:
A session factory has already been configured with the key of nhibernate.current_session
I have even tried loading them in separate Application Pools and the error persists. I don’t understand how is it that my two applications’ sessions are colliding on IIS, whereas they run just fine with Visual Studio.
FYI, I am trying to run them on Windows Server 2008 R2 + IIS 7.5
Any help?
It looks like S#arp Architecture tries to use the same NHibernate session factory for both applications. It maybe colliding because it uses the same default ‘factory key’ (nhibernate.current_session) for both web apps when it persists configuration on disk. Should you be using different ‘factory keys’? In order to do this you can read the FAQ section about multiple databases (although you don’t have multiple databases, your solution may be the same):
Looking at S#arp sources I found that they use following logic to create file on disk:
So if you don’t want to change config/factory key you can try calling this code from different assembly.
EDIT:
It looks like
NHibernateSession.Initdoes not take overload that lets you specify factory key. But it has other public methods that you can call instead of Init: