Out of the blue Null Reference Exception

Oct 10, 2007 at 2:06 PM
Out of the blue, I got the following exception when starting up my WCSF application:

Exception information:
Exception type: NullReferenceException
Exception message: Object reference not set to an instance of an object.

More details:
Thread information:
Thread ID: 1
Is impersonating: False
Stack trace: at Microsoft.Practices.CompositeWeb.WebClientApplication.GetModuleContainer(IHttpContext context)
at Microsoft.Practices.CompositeWeb.WebClientApplication.InnerPreRequestHandlerExecute(IHttpContext context)
at Microsoft.Practices.CompositeWeb.WebClientApplication.Application_PreRequestHandlerExecute(Object sender, EventArgs e)
at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

What was my fix? I copied the project's dll's back over to the deployment.

Three questions:
1. Has anyone else had this happen?
2. Any theories on why it would suddenly happen?
3. Why would redeploying the dll's fix it?

Charles Sustek
Triad Financial Corporation
Nov 4, 2008 at 5:21 PM
Edited Nov 4, 2008 at 5:22 PM
I've had the same (or similar) problem, my callstack was:

Microsoft.Practices.CompositeWeb.WebClientApplication.GetModuleContainer(IHttpContext context) in c:\Builds\WCSFv2-BlocksCI\PublishBinariesBuildTemp\Source\CompositeWeb\Source\CompositeWeb\WebClientApplication.cs:164 Microsoft.Practices.CompositeWeb.WebClientApplication.BuildItemWithCurrentContext(Object obj) in c:\Builds\WCSFv2-BlocksCI\PublishBinariesBuildTemp\Source\CompositeWeb\Source\CompositeWeb\WebClientApplication.cs:353 Microsoft.Practices.CompositeWeb.Web.UI.Page.OnPreInit(EventArgs e) in c:\Builds\WCSFv2-BlocksCI\PublishBinariesBuildTemp\Source\CompositeWeb\Source\CompositeWeb\Web\UI\Page.cs:38 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +663

I believe it was caused by having conflicting information in the global.asax and global.asax.cs files. In the global.asax I had

<%@ Application Codebehind="Global.asax.cs" Inherits="WebApplication.Global" Language="C#" %>

whereas the global.asax.cs correctly tried to inherit from Microsoft.Practices.CompositeWeb.WebClientApplication:

public class Global : Microsoft.Practices.CompositeWeb.WebClientApplication

The exception went away after fixing the global.asax to

<%@ Application Codebehind="Global.asax.cs" Inherits="Microsoft.Practices.CompositeWeb.WebClientApplication" Language="C#" %>

Hth anyone finding this page via google...

Nov 4, 2008 at 7:19 PM
I just realized, that when I change global.asax as above, obviously whatever i have in my global.asax.cs is ignored. When I try to use code in global.asax.cs, I again get the NullReference exception, which is pretty weird as I had it working ealier today...
Nov 4, 2008 at 7:24 PM
Turns out that when you override Application_Start, the null exception error occurs, when you forget to call base.Application_Start first.
May 27, 2009 at 4:06 PM

This really helped... Just changing the global.asax did the trick. Good one. Many Thanks.

Aug 27, 2013 at 4:00 AM
Thanks, bschwehn, that was my error.