I am using .NET 4 and NHibernate v3.3.4
So I haven't been able to reproduce this error. It is produced every few days seemingly at random.
The stacktrace is as follows.
System.NullReferenceException: Object reference not set to an instance of an object.
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at System.Collections.Generic.Dictionary`2.set_Item(TKey key, TValue value)
at NHibernate.Impl.SessionFactoryObjectFactory.AddInstance(String uid, String name, ISessionFactory instance, IDictionary`2 properties)
at NHibernate.Impl.SessionFactoryImpl..ctor(Configuration cfg, IMapping mapping, Settings settings, EventListeners listeners)
at NHibernate.Cfg.Configuration.BuildSessionFactory()
at OmsDalNhib.OmsDalConfig.GetSessionFactory()
at OrmsReport.Extensions.Extensions.ZoneList() in d:\temp\src\OrmsReport\Extensions\Extensions.cs:line 129
at OrmsReport.Controllers.ReportController.OutageSummaryMobile(String outagesummaryfilters, String zones, String customers) in d:\temp\src\OrmsReport\Controllers\ReportController.cs:line 149
at lambda_method(Closure , ControllerBase , Object[] )
at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass42.<BeginInvokeSynchronousActionMethod>b__41()
at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass37.<>c__DisplayClass39.<BeginInvokeActionMethodWithFilters>b__33()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass37.<BeginInvokeActionMethodWithFilters>b__36(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass25.<>c__DisplayClass2a.<BeginInvokeAction>b__20()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult)
The line that seems to be throwing the error is
var session = new OmsDalConfig(BuildConfiguration.GetConnectionString())
.GetSessionFactory().OpenSession()
This issue seemed related, and I replicated their solution by locking the line above. Which unfortunately did not solve anything.
Thanks in advance if anyone has suggestions. And let me know if I ccan provide any other neccesary information
Edit:
BuildConfiguration.GetConnectionString()
returns a string of the form
"Data Source=(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = myserver.com)(PORT = 6667)))(CONNECT_DATA =(SERVICE_NAME = my-service)));User ID=myuser;Password=mypassword;";
Edit 2:
As requested:
Constructor for OMSDalConfig is just assigning the connection string, and the SessionFactory is not being built every time, at least it doesnt appear so.
public class OmsDalConfig
{
private readonly string _connectionString;
public static ISessionFactory CurrentSessionFactory;
public OmsDalConfig(string connectionString)
{
_connectionString = connectionString;
}
public ISessionFactory GetSessionFactory()
{
// Models
var modelMapper = new ModelMapper();
var mappingTypes = typeof(IncidentMap).Assembly.GetExportedTypes().Where(x => x.Name.EndsWith("Map")).ToArray();
modelMapper.AddMappings(mappingTypes);
// NHibernate config
var nhibernateConfig = new Configuration()
.DataBaseIntegration(db =>
{
db.Dialect<Oracle10gDialect>();
db.ConnectionString = _connectionString;
db.Driver<OracleClientDriver>();
});
nhibernateConfig.AddMapping(modelMapper.CompileMappingForAllExplicitlyAddedEntities());
if (CurrentSessionFactory != null)
{
return CurrentSessionFactory;
}
CurrentSessionFactory = nhibernateConfig.BuildSessionFactory();
return CurrentSessionFactory;
}
}
I will try separating the session var assignment as discussed and report back. Apologies for the late reply. Thank you all again for the help.
Edit3:
I have separated the OpenSession and Build Session calls when creating the session variable (line that is throwing the exception). Ill leave it running for a while and report back if there error is thrown again or not.
Edit 4 : As stated in Edit 3. I tried splitting the calls. There error was thrown again today so thats a no go. Any other suggestions are greatly appreciated.