While using Spring.NET and NHibernate on a ASP.NET web application I came across the following error:
System.Data.SqlClient.SqlException: Incorrect syntax for definition of the 'TABLE' constraint.
NHibernate.HibernateException: Incorrect syntax for definition of the 'TABLE' constraint.
The problem was that I was trying to name a column in a SQL Server database as "References", which must be a protected name because it didn't like it. When I changed my code to call the column "Refs" instead the problem went away.
[Property(Name = "Refs", Column = "References", Length = 4001)]
//Length 4001 is equivalent to nvarchar(MAX)
public virtual string Refs { get; protected internal set; }
Showing posts with label NHibernate. Show all posts
Showing posts with label NHibernate. Show all posts
Thursday, 28 January 2010
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.
[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.
Labels:
ASP.NET,
IIS,
IIS7,
MVC,
NHibernate,
Spring.NET
Subscribe to:
Posts (Atom)