views:

297

answers:

1

I have a large, complicated web site, mostly written by other people. I've made some changes, and now when I try to access any page on the site (not just where my changes are), I get the error described below. While I'd like to know how to fix this problem, I'd even more like to know the general diagnostic steps I should take next in order to track down the problem - I'd like to be able to solve it myself next time. Thanks in advance for the help!

When I navigate a browser to any page on the site, I get a server error back:

Parser Error
Parser Error Message: Object reference not set to an instance of an object.
Source Error: [No relevant source lines]

I checked the event log on the server, and got some slightly more detailed information:

Event code: 3006 
Event message: A parser error has occurred. 

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

Stack trace:
at System.Web.Compilation.BuildManager.ReportTopLevelCompilationException()
at System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled()
at System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters)
+2  A: 

1) The source error is not showing any lines or line numbers so make sure you are doing a debug build. Also, ensure that you have under in you web.config file.

2) Check your global.asax file ... something is probably wrong there. You have a null reference exception and it's probably happening in any code you've changed in global.asax.cs.

EDIT: To debug your global.asax.cs file, it's often easiest to place a System.Diagnostics.Debugger.Launch() call in your Session_Start event handler. Add the handler if you don't have one.

3) Check to make sure that ASP.NET is installed correctly. There is a tab named ASP.NET in the properties of your virtual directory in IIS. Check the version. If it's not installed correctly, run "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis -i".

4) If you are using VS, then go CTRL-ALT-E (or Debug/Exceptions menu), and check the Thrown option for Common Language Runtime Exceptions, so VS will break whenever a CLR exception is thrown, then you can see exactly where it's happening. Launch the application in the debugger and find out what's going on.

5) If the exception is thrown outside of your code, check the stack trace to find out where it's coming from.

6) If you have to go much deeper, and you know it's happening in .NET but you don't know why, enable .NET Framework source code stepping (it's in Options/Debug someplace if you are using VS2008 SP1). If you are using an earlier version, you'll have to look up how to enable the .NET Framework symbols etc.... You shouldn't have to do this though, just adding it as the "next step".

Richard Hein
Thanks for the pointers! It turned out to be a combination of configuration problems, which was pulling in stale components, which was breaking some code generation the site was doing. Some other folks on the team put me on the chance, so fortunately or unfortunately I didn't get much chance to practice the debugging tips you described. Maybe next time.
Bruce