Last post Mar 30, 2012 04:55 PM by jordantx
Mar 29, 2012 03:18 PM|jordantx|LINK
I'm using Visual Studio 2010 and C# ASP.NET. When I run my project using F5 key, it launches the ASP.NET Development Server, and that's the server I'm using for my work, not IIS.
Problem is, when I get a "Server error in / application" unhandled exception error, the error page has no line numbers, nor source file name. Just an error description and stack trace. For example:
Server Error in '/' Application.
DataField must be specified. [or whatever error message]
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.InvalidOperationException: DataField must be specified.
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.
I am compiling in Debug mode. My PDB is being generated in my project's BIN directory. In my project properties, under Web, NTLM authentication is turned off. In my web.config I have the following:
<compilation debug="true" targetFramework="4.0">
Also in my project properties, under Build, the Debug configuration is active, and the DEBUG and TRACE constant checkboxes are turned on. Under Advanced, the Internal Compiler Error Reporting is set True, and Debug Info is set to Full.
The user account I am running under has "Debug Programs" privilege enabled in its group's security policy.
I have researched this question here, and on StackOverflow and elsewhere, but I can't seem to find a straight answer that fits my situation. One answer I found involved removing a setting "impersonate=true" from web.config, which apparently applies to IIS,
but I'm not using IIS, nor do I have this in my config file. I'm using the built-in ASP.NET Development Server which comes with VS 2010, instead of IIS. Another answer said to set up a symbol server, and set the _NT_SYMBOL_PATH env variable, but I don't know
if this applies to what I'm doing.
This is really confusing because I'm using default settings and configuration for everything, and it seems like this would be a common problem most developers would encounter. Unless everyone else is using Publish and doing their development via IIS. Incidentally
I tried with IIS and I do get line numbers, source code, etc. in the error messages. But I want to use the built-in ASP.NET Development Server -- I would expect it to show full debug/trace details for exceptions by default, and maybe even integrate with VS
2010 to break on exceptions and let me step through code. But maybe I'm asking for too much. Anyone?
(If you answer with a suggested solution, please first read the details of my settings above, so you can see whether I already have the setting you're suggesting.)
Mar 29, 2012 03:22 PM|d4daud|LINK
Are you using parenthesis in the parent folder name of the website?
Mar 29, 2012 03:28 PM|jordantx|LINK
Actually yes I am d4daud, how did you know? Psychic or something?
So I'm guessing that's the cause of this, eh? Anyone have a link to a knowledge base article or tech note on this? I'll remove the parens and see what happens... But this will probably require manual editing of the SLN and CSPROJ files, and possibly other
files... Any tips appreciated.
Mar 29, 2012 03:31 PM|jordantx|LINK
Just to clarify: The folder in which the SLN resides has parentheses in the name. From there, the CSPROJ and other files are in a subfolder. So it's the "folder name of the solution", not "folder name of the
website" which would seem to refer to IIS folders, and I'm not using IIS.
Mar 30, 2012 09:04 AM|jordantx|LINK
I removed the parentheses from the folder name and solution file name, but still no line numbers or source file name/excerpt. Argh! Can anyone help?
Mar 30, 2012 04:55 PM|jordantx|LINK
So, I figured out that line numbers were showing up fine when a .CS source file threw an exception, but not when an exception occurred in an ASPX page. For the ASPX itself, the line number & source code were not appearing at all, whether in IIS or Development
Server. One of my colleagues said this is just the behavior, there's no way around it. He implied that you will have to guess which line the exception is on in your ASPX page.
However, after more research, I found a way! I can get the line numbers when an ASPX page throws an exception. But I still don't understand why this isn't any easier to set up! Like maybe an option at the page or project level, instead of requiring a
block of code to be added.
The following code must be in each page's ASPX.CS itself,
not in its Master Page, nor in any parent class derived from Page class (which the page may inherit from). This is because if the other classes' Page_Error handlers are called instead, the call stack is
affected, and the most recent entry doesn't pertain to the error. (I was looking into a solution for this too. It appears to be possible, but I ran out of time and gave up for now.)
public void Page_Error(object sender, EventArgs e)
Exception objErr = Server.GetLastError().GetBaseException();
StackTrace st = new StackTrace(new StackFrame(true));
StackFrame sf = st.GetFrame(0);
Response.Write("File Name: " + sf.GetFileName().ToString() + "<br>");
Response.Write("Method Name: " + sf.GetMethod().Name.ToString() + "<br>");
Response.Write("Error Line Number: " + (sf.GetFileLineNumber() - 1) + "<br>"); // line numbers are offset by 1 for some reason
Response.Write("Error Column Number: " + sf.GetFileColumnNumber().ToString() + "<br>");