I'm getting an error and I don't know why!

Apr 2, 2009 at 2:43 PM
Hi,

I'm a newbie to ASP.NET MVC and am getting the following error when I run the app. The strange thing is that when I set a breakpoint on the line preceding the one that gives the error (HttpContextBase context = filterContext.HttpContext;) and step through the code from there on, the error goes away and it works fine! By th way I am using MVC Release version 1

Any ideas?

Thanks
Paul


<title>Object reference not set to an instance of an object.</title> <style> BODY { FONT-WEIGHT: normal; FONT-SIZE: 0.7em; COLOR: black; FONT-FAMILY: "Verdana" } P { MARGIN-TOP: -5px; FONT-WEIGHT: normal; COLOR: black; FONT-FAMILY: "Verdana" } B { MARGIN-TOP: -5px; FONT-WEIGHT: bold; COLOR: black; FONT-FAMILY: "Verdana" } H1 { FONT-WEIGHT: normal; FONT-SIZE: 18pt; COLOR: red; FONT-FAMILY: "Verdana" } H2 { FONT-WEIGHT: normal; FONT-SIZE: 14pt; COLOR: maroon; FONT-FAMILY: "Verdana" } PRE { FONT-SIZE: 0.9em; FONT-FAMILY: "Lucida Console" } .marker { FONT-WEIGHT: bold; COLOR: black; TEXT-DECORATION: none } .version { COLOR: gray } .error { MARGIN-BOTTOM: 10px } .expandable { FONT-WEIGHT: bold; CURSOR: hand; COLOR: navy; TEXT-DECORATION: underline } </style>

Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 12:             HttpContextBase context = filterContext.HttpContext;
Line 13: 
Line 14:             string acceptEncoding = context.Request.Headers["Accept-Encoding"];
Line 15: 
Line 16:             if (!string.IsNullOrEmpty(acceptEncoding))

Source File: C:\Work\FlickrXplorer.Src\FlickrXplorer.Web\CompressResponseAttribute.cs    Line: 14

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.]
   FlickrXplorer.Web.CompressResponseAttribute.OnActionExecuting(ActionExecutingContext filterContext) in C:\Work\FlickrXplorer.Src\FlickrXplorer.Web\CompressResponseAttribute.cs:14
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +47
   System.Web.Mvc.<>c__DisplayClassc.<InvokeActionMethodWithFilters>b__9() +19
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +254
   System.Web.Mvc.<>c__DisplayClassc.<InvokeActionMethodWithFilters>b__9() +19
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +192
   System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +399
   System.Web.Mvc.Controller.ExecuteCore() +126
   System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +27
   System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +7
   System.Web.Mvc.MvcHandler.ProcessRequest(HttpContextBase httpContext) +151
   System.Web.Mvc.MvcHandler.ProcessRequest(HttpContext httpContext) +57
   System.Web.Mvc.MvcHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext httpContext) +7
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75

Apr 2, 2009 at 8:14 PM
Hi Paul,
Reason,  beacause request.Context is coming null. i have added a patch at the source tab, please download it and give a try. I will add a new version tested in 1.0 in a day or two.

Hope that Helps,
Mehfuz.
Apr 15, 2009 at 6:01 PM
Thanks a lot Mehfuz, I realised what it was, just not why it was happening. Thanks for the patch though.
Cheers
Paul


From: [email removed]
To: [email removed]
Date: Thu, 2 Apr 2009 12:14:28 -0700
Subject: Re: I'm getting an error and I don't know why! [FlickrXplorer:52075]

From: mehfuzh
Hi Paul,
Reason, beacause request.Context is coming null. i have added a patch at the source tab, please download it and give a try. I will add a new version tested in 1.0 in a day or two.

Hope that Helps,
Mehfuz.


Invite your mail contacts to join your friends list with Windows Live Spaces. It's easy! Try it!