Friday 6 November 2009

Argument 'Key must not be null' cannot be null.

Occasionally during development within an ASP.NET (MVC)/NHibernate/Spring.NET environment I come across the above, rather cryptic, error. In full the stack trace looks like this:


[ArgumentNullException: Argument 'Key must not be null' cannot be null.
Parameter name: Key must not be null]
Spring.Util.AssertUtils.ArgumentNotNull(Object argument, String name) +203
Spring.Transaction.Support.TransactionSynchronizationManager.HasResource(Object key) +68
Spring.Data.NHibernate.Support.SessionScope.Open() +246
Spring.Data.NHibernate.Support.OpenSessionInViewModule.context_BeginRequest(Object sender, EventArgs e) +47
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +68
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75


Usually this occurs following a fresh deployment to an IIS7 environment. Some guy here reckons it's something to do with the OpenSessionInView class not finding a suitable session factory but I'm not so sure.

The bottom line is, that if you open up your web.config file, make a change (i.e. add/remove some blank space) and save it, then when you refresh the page the error will go away. Occasionally there is another error which was hidden by the first, but usually the web application works fine at this point. This is only a workaround, but the error only appears immediately after a deployment, and once fixed doesn't reappear so it's good enough for me.

No comments:

Post a Comment