0

The web application is asp mvc. I can't figure out what object reference not set to an instance of an object means. Is it database related or some ajax failing? I am not familiar with ASP MVC apps. And when I try to go to admin page, Index.apsx keeps getting injected in the wrong place in the url, what causes that?

Server Error in '/' Application.

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:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.]
BoatingSafety.Utils.CreateContext() in C:\inetpub\wwwroot\AppDevProjects\ASP.NET\BoatingSafety\BoatingSafety\SupportClasses\Utils.cs:27
BoatingSafety.Controllers.PageController.Index() in C:\inetpub\wwwroot\AppDevProjects\ASP.NET\BoatingSafety\BoatingSafety\Controllers\PageController.cs:31
lambda_method(ExecutionScope , ControllerBase , Object[] ) +40
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +17
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +178
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +24
System.Web.Mvc.<>c__DisplayClassd.<InvokeActionMethodWithFilters>b__a() +53
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +258
System.Web.Mvc.<>c__DisplayClassf.<InvokeActionMethodWithFilters>b__c() +20
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +193
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +300
System.Web.Mvc.Controller.ExecuteCore() +104
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +36
System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +7
System.Web.Mvc.MvcHandler.ProcessRequest(HttpContextBase httpContext) +59
System.Web.Mvc.MvcHandler.ProcessRequest(HttpContext httpContext) +54
System.Web.Mvc.MvcHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext httpContext) +7
System.Web.Mvc.MvcHttpHandler.VerifyAndProcessRequest(IHttpHandler httpHandler, HttpContextBase httpContext) +54
System.Web.Routing.UrlRoutingHandler.ProcessRequest(HttpContextBase httpContext) +111
System.Web.Routing.UrlRoutingHandler.ProcessRequest(HttpContext httpContext) +40
System.Web.Routing.UrlRoutingHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext context) +7
BoatingSafety._Default.Page_Load(Object sender, EventArgs e) in C:\inetpub\wwwroot\AppDevProjects\ASP.NET\BoatingSafety\BoatingSafety\Default.aspx.cs:22
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +50
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627
sxb
  • 1
  • 1
  • You are calling a method/property on a reference that is null. (e.g. `object o = null; o.ToString();` - obviously this is typically a bit more complicated than this but this is what it boils down to) – Pawel Jul 14 '15 at 18:16

1 Answers1

1

NullReferenceException is a generic exception.

When you get this error, it means that somewhere in your project there is a non nullable protected sample of code or in other words, you are trying to call something that is null.

Example:

Class1 obj = new Class1();
obj.Prop1 = 0; // This is ok
obj = null; 
obj.Prop1 = 0; // This will throw System.NullReferenceException

See also

NullReferenceException Class

What is a NullReferenceException and how do I fix it?

Also:

Utils.CreateContext() in C:\inetpub\wwwroot\AppDevProjects\ASP.NET\BoatingSafety\BoatingSafety\SupportClasses\Utils.cs:27

PageController.Index() in C:\inetpub\wwwroot\AppDevProjects\ASP.NET\BoatingSafety\BoatingSafety\Controllers\PageController.cs:31

It occurs at the class Utils in the function CreateContext Line 27 and then bubble up to /Page/Index Line 31

PDB in production server

It seems that you have PDB in your client production server. It's not recommended.

See More

Community
  • 1
  • 1
Leandro Soares
  • 2,902
  • 2
  • 27
  • 39
  • Having PDB symbol files in production isn't such a bad idea (Microsoft symbol server uses this approach), but it would be better to have a generic error handler page/view to display a generic "Something went wrong" type message. In the background, log the exception, with stack trace, somewhere out of the user's site. – Jason Evans Jul 14 '15 at 21:08
  • I agree with you, that's a very important User Experience topic, always log the exception and notify the user with a custom page. As i've read about PDB files, they make the application slower altough i've never experienced it. And i believe that PDB contains sensitive data about the code like the names of all local variables and source code files, and if you use some obfuscation that can be harmfull (?), that's what i think. – Leandro Soares Jul 14 '15 at 21:12