View Full Version : Problem with OpenSessionInViewModule: NullReferenceException
Flozano
02-07-2007, 05:23 PM
Hello,
I'm using latest Spring NHibernate module (with NHibernate 1.2beta3 support). I'm using Visual Studio 2005's development internal webserver.
We're getting a NullReferenceException:
[NullReferenceException: Referencia a objeto no establecida como instancia de un objeto.]
Spring.Data.NHibernate.Support.OpenSessionInViewMo dule.get_Participate() +52
Spring.Data.NHibernate.Support.OpenSessionInViewMo dule.Close() +49
Spring.Data.NHibernate.Support.OpenSessionInViewMo dule.context_EndRequest(Object sender, EventArgs e) +45
System.Web.SyncEventExecutionStep.System.Web.HttpA pplication.IExecutionStep.Execute() +92
System.Web.HttpApplication.ExecuteStep(IExecutionS tep step, Boolean& completedSynchronously) +64
I've seen that the Participate property has been altered in changeset MAIN:oakinger:20070129183509, and now it contains...
/// <summary>
/// Gets/Sets a flag, whether this module manages it's own session for the current request or not.
/// </summary>
/// <value><c>false</c> if session is managed by this module. <c>false</c> otherwise</value>
private bool Participate
{
get { return (bool)LogicalThreadContext.GetData( PARTICIPATE_KEY ); }
set { LogicalThreadContext.SetData(PARTICIPATE_KEY, value); }
So maybe the LogicalThreadContext.GetData is returning NULL? casting a NULL to bool throws this NullReferenceException, right?
Thanks...
Flozano
02-07-2007, 06:22 PM
We've tested this problem only happens in the first call to the webpage.
Remember we're using VS2005's embedded webserver. Maybe in IIS this problem doesn't arise?
thankz
Erich Eichinger
02-07-2007, 07:44 PM
Hi,
Can you please reproduce this problem using a debug build of spring/spring.data.nhibernate?
Are you using "WebContextHandler" (vs. "DefaultContextHandler") for your <spring/context> configuration section? See here (http://forum.springframework.net/showthread.php?p=3171) on correctly configuring a web application.
cheers,
Erich (aka "oakinger" ;-))
Flozano
02-07-2007, 11:18 PM
I'm using latest SpringModule 1.2 build, with the DLLs in the Debug directory.
I'm using, of course, a WebApplicationContext.
Flozano
02-07-2007, 11:22 PM
Uhm do I have to use this Spring.Web.Support.PageHandlerFactory even if I don't use Page injection? it's the only thing it's different than the provided URL... tomorrow I'll try it...
Erich Eichinger
02-08-2007, 06:18 AM
Hi,
If you don't use Page injection, then you don't need PageHandlerFactory.
I'm using, of course, a WebApplicationContext.
The reason I was asking is that it is a common mistake (and unfortunately not obvious if forgotten) to leave "Spring.Context.Support.ContextHandler, Spring.Core" as sectionhandler for section <spring/context> instead of changing it to "Spring.Context.Support.WebContextHandler, Spring.Web". WebContextHandler is vital for enabling a couple of web-related settings.
I'll try to reproduce the problem on my box. Could you maybe configure logging at DEBUG level and send me the log output of the request resulting in this error?
tx,
Erich
Flozano
02-08-2007, 05:33 PM
Here is it (quite verbose).
There's nothing else after that request (the only one made to the server).
...
2007-02-08 18:27:42,391 [DEBUG] Spring.Context.Support.WebApplicationContext - created instance [/m2.web.backoffice]:WebApplicationContext(52272470)
2007-02-08 18:27:42,391 [DEBUG] Spring.Context.Support.ContextRegistry - Registering context '[/m2.web.backoffice]:WebApplicationContext(52272470)' under name '/m2.web.backoffice'.
2007-02-08 18:27:42,391 [DEBUG] Spring.Context.Support.ContextHandler - context '[/m2.web.backoffice]:WebApplicationContext(52272470)' created for name '/m2.web.backoffice'
2007-02-08 18:27:42,391 [DEBUG] Spring.Context.Support.ContextRegistry - Returning context '[/m2.web.backoffice]:WebApplicationContext(52272470)' registered under name '/m2.web.backoffice'.
2007-02-08 18:27:42,391 [DEBUG] Spring.Objects.Factory.Support.WebObjectFactory - Returning cached instance of singleton object 'SessionFactory'.
2007-02-08 18:27:42,391 [DEBUG] Spring.Objects.Factory.Support.WebObjectFactory - Object with name 'SessionFactory' is a factory object.
2007-02-08 18:27:42,391 [DEBUG] Spring.Data.NHibernate.Support.OpenSessionInViewMo dule - Creating LazySessionHolder in OpenSessionInView
2007-02-08 18:27:42,391 [DEBUG] Spring.Data.NHibernate.Support.OpenSessionInViewMo dule+LazySessionHolder - Created LazySessionHolder
2007-02-08 18:27:42,407 [DEBUG] Spring.Transaction.Support.TransactionSynchronizat ionManager - Bound value [Spring.Data.NHibernate.Support.OpenSessionInViewMo dule+LazySessionHolder] for key [NHibernate.Impl.SessionFactoryImpl] to thread []
2007-02-08 18:27:42,438 [DEBUG] Spring.Context.Support.WebApplicationContext - looking up web context '/M2.Web.Backoffice/' in WebContextCache
2007-02-08 18:27:42,438 [DEBUG] Spring.Context.Support.WebApplicationContext - looking up web context '/M2.Web.Backoffice/' in ContextRegistry
2007-02-08 18:27:42,438 [DEBUG] Spring.Context.Support.WebApplicationContext - web context for vpath '/M2.Web.Backoffice/' not found. Force creation using filepath '/M2.Web.Backoffice/default.aspx'
2007-02-08 18:27:42,438 [DEBUG] Spring.Context.Support.WebApplicationContext - got context '[/m2.web.backoffice]:WebApplicationContext(52272470)' for vpath '/M2.Web.Backoffice/'
2007-02-08 18:27:42,438 [DEBUG] Spring.Context.Support.WebApplicationContext - added context '[/m2.web.backoffice]:WebApplicationContext(52272470)' to WebContextCache for vpath '/M2.Web.Backoffice/'
2007-02-08 18:27:42,438 [DEBUG] Spring.Context.Support.WebApplicationContext - added parent context '[/m2.web.backoffice]:WebApplicationContext(52272470)' to WebContextCache for vpath '/m2.web.backoffice'
2007-02-08 18:27:42,438 [DEBUG] Spring.Util.WebUtils - getting page type for /M2.Web.Backoffice/default.aspx
2007-02-08 18:27:42,438 [DEBUG] Spring.Util.WebUtils - page vpath is /M2.Web.Backoffice/default.aspx
2007-02-08 18:27:42,688 [DEBUG] Spring.Util.WebUtils - got page type 'ASP.default_aspx' for vpath '/M2.Web.Backoffice/default.aspx'
2007-02-08 18:27:42,688 [DEBUG] Spring.Util.WebUtils - creating page instance '/M2.Web.Backoffice/default.aspx'
2007-02-08 18:27:42,688 [DEBUG] Spring.Util.WebUtils - page vpath is /M2.Web.Backoffice/default.aspx
2007-02-08 18:27:42,782 [DEBUG] Spring.Context.Support.WebApplicationContext - looking up web context '/M2.Web.Backoffice/' in WebContextCache
2007-02-08 18:27:42,782 [DEBUG] Spring.Context.Support.WebApplicationContext - returning WebContextCache hit '[/m2.web.backoffice]:WebApplicationContext(52272470)' for vpath '/M2.Web.Backoffice/'
2007-02-08 18:27:42,782 [DEBUG] Spring.Objects.Factory.Support.WebObjectFactory - Returning cached instance of singleton object 'SessionFactory'.
2007-02-08 18:27:42,782 [DEBUG] Spring.Objects.Factory.Support.WebObjectFactory - Object with name 'SessionFactory' is a factory object.
2007-02-08 18:27:42,876 [INFO ] NHibernate.Loader.Loader - select countryent0_.country_id as country1_1_, countryent0_.modified_at as modified2_1_, countryent0_.audit_id as audit3_1_, countryent0_.audited as audited1_, countryent0_.creator as creator1_, countryent0_.modifier as modifier1_, countryent0_.description as descript7_1_, countryent0_.created_at as created8_1_, countryent0_.name as name1_ from country countryent0_
2007-02-08 18:27:42,970 [DEBUG] Spring.Objects.Factory.Support.WebObjectFactory - disposing 'request'-scoped item cache
There's nothing else after that request (the only one made to the server).
Flozano
02-08-2007, 05:36 PM
By the way,
Subsequent request (which don't fail) log like this:
2007-02-08 18:34:49,481 [DEBUG] Spring.Data.NHibernate.Support.OpenSessionInViewMo dule - Creating LazySessionHolder in OpenSessionInView
2007-02-08 18:34:49,481 [DEBUG] Spring.Data.NHibernate.Support.OpenSessionInViewMo dule+LazySessionHolder - Created LazySessionHolder
2007-02-08 18:34:49,481 [DEBUG] Spring.Transaction.Support.TransactionSynchronizat ionManager - Bound value [Spring.Data.NHibernate.Support.OpenSessionInViewMo dule+LazySessionHolder] for key [NHibernate.Impl.SessionFactoryImpl] to thread []
2007-02-08 18:34:49,481 [DEBUG] Spring.Util.WebUtils - creating page instance '/M2.Web.Backoffice/default.aspx'
2007-02-08 18:34:49,481 [DEBUG] Spring.Util.WebUtils - page vpath is /M2.Web.Backoffice/default.aspx
2007-02-08 18:34:49,481 [DEBUG] Spring.Context.Support.WebApplicationContext - looking up web context '/M2.Web.Backoffice/' in WebContextCache
2007-02-08 18:34:49,481 [DEBUG] Spring.Context.Support.WebApplicationContext - returning WebContextCache hit '[/m2.web.backoffice]:WebApplicationContext(52272470)' for vpath '/M2.Web.Backoffice/'
2007-02-08 18:34:49,481 [DEBUG] Spring.Objects.Factory.Support.WebObjectFactory - Returning cached instance of singleton object 'SessionFactory'.
2007-02-08 18:34:49,481 [DEBUG] Spring.Objects.Factory.Support.WebObjectFactory - Object with name 'SessionFactory' is a factory object.
2007-02-08 18:34:49,497 [INFO ] NHibernate.Loader.Loader - select countryent0_.country_id as country1_1_, countryent0_.modified_at as modified2_1_, countryent0_.audit_id as audit3_1_, countryent0_.audited as audited1_, countryent0_.creator as creator1_, countryent0_.modifier as modifier1_, countryent0_.description as descript7_1_, countryent0_.created_at as created8_1_, countryent0_.name as name1_ from country countryent0_
2007-02-08 18:34:49,497 [DEBUG] Spring.Data.NHibernate.Support.OpenSessionInViewMo dule - Closing LazySessionHolder in OpenSessionInView
2007-02-08 18:34:49,497 [DEBUG] Spring.Data.NHibernate.Support.OpenSessionInViewMo dule+LazySessionHolder - Closed LazySessionHolder
2007-02-08 18:34:49,966 [DEBUG] Spring.Data.NHibernate.Support.OpenSessionInViewMo dule - Creating LazySessionHolder in OpenSessionInView
2007-02-08 18:34:49,966 [DEBUG] Spring.Data.NHibernate.Support.OpenSessionInViewMo dule+LazySessionHolder - Created LazySessionHolder
2007-02-08 18:34:49,966 [DEBUG] Spring.Transaction.Support.TransactionSynchronizat ionManager - Bound value [Spring.Data.NHibernate.Support.OpenSessionInViewMo dule+LazySessionHolder] for key [NHibernate.Impl.SessionFactoryImpl] to thread []
2007-02-08 18:34:49,966 [DEBUG] Spring.Util.WebUtils - creating page instance '/M2.Web.Backoffice/default.aspx'
2007-02-08 18:34:49,966 [DEBUG] Spring.Util.WebUtils - page vpath is /M2.Web.Backoffice/default.aspx
2007-02-08 18:34:49,966 [DEBUG] Spring.Context.Support.WebApplicationContext - looking up web context '/M2.Web.Backoffice/' in WebContextCache
2007-02-08 18:34:49,966 [DEBUG] Spring.Context.Support.WebApplicationContext - returning WebContextCache hit '[/m2.web.backoffice]:WebApplicationContext(52272470)' for vpath '/M2.Web.Backoffice/'
2007-02-08 18:34:49,966 [DEBUG] Spring.Objects.Factory.Support.WebObjectFactory - Returning cached instance of singleton object 'SessionFactory'.
2007-02-08 18:34:49,966 [DEBUG] Spring.Objects.Factory.Support.WebObjectFactory - Object with name 'SessionFactory' is a factory object.
2007-02-08 18:34:49,966 [INFO ] NHibernate.Loader.Loader - select countryent0_.country_id as country1_1_, countryent0_.modified_at as modified2_1_, countryent0_.audit_id as audit3_1_, countryent0_.audited as audited1_, countryent0_.creator as creator1_, countryent0_.modifier as modifier1_, countryent0_.description as descript7_1_, countryent0_.created_at as created8_1_, countryent0_.name as name1_ from country countryent0_
2007-02-08 18:34:49,966 [DEBUG] Spring.Data.NHibernate.Support.OpenSessionInViewMo dule - Closing LazySessionHolder in OpenSessionInView
2007-02-08 18:34:49,966 [DEBUG] Spring.Data.NHibernate.Support.OpenSessionInViewMo dule+LazySessionHolder - Closed LazySessionHolder
Erich Eichinger
02-08-2007, 05:55 PM
Hi,
I think I've got an idea what is causing this error. But I have to think about how to solve it.
In the meantime could you place the following lines in the static constructor of your HttpApplication/Global.asax class:
// Global.asax.cs:
public class MyHttpApplication : HttpApplication
{
static MyHttpApplication()
{
object dummy = new Spring.Context.Support.WebContextHandler();
}
...
}
and see, if the problem goes away?
tx a lot for your help and reporting this!
cheers,
Erich
Flozano
02-08-2007, 07:43 PM
The fix worked perfect... I guess it's just a workaround but it works. THANKX!
Erich Eichinger
02-08-2007, 07:48 PM
yes, it's only workaround until I've found a better solution - which hopefully won't last to long.
Tx for trying it - and verifying my theorie.
cheers,
Erich
Erich Eichinger
02-09-2007, 05:01 PM
Hi,
I recorded and fixed this bug in JIRA as SPRNET-476 (http://opensource.atlassian.com/projects/spring/browse/SPRNET-476)
You should get the fix with the next nightly build and can safely remove the workaround from your code
cheers,
Erich
Flozano
02-09-2007, 10:01 PM
Hi,
I recorded and fixed this bug in JIRA as SPRNET-476 (http://opensource.atlassian.com/projects/spring/browse/SPRNET-476)
You should get the fix with the next nightly build and can safely remove the workaround from your code
cheers,
Erich
Thanks :))
Powered by vBulletin® Version 4.1.5 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.