Stack trace in website project, when debug = false - asp.net

We have a website project. We are logging unhanded exceptions via a appdomain level exception handler.
When we set debug= true in web.config, the exception log is showing the offending line numbers in the stack trace.
But when we set debug = false, in web.config, log is not displaying the line numbers.
We are not in a position to convert the website project in to webapplication project type at this time. Its legacy application and almost all the code is in aspx pages. We also need to leave the project in 'updatable' mode. i.e. We can't user pre-compile option. We are generating pdb files.
Is there anyway to tell this kind of website projects to generate the pdb files, and show the line numbers in the stack trace?

Add compilerOptions="/debug:pdbonly" as an attribute to <compiler> in your web.config file:
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" compilerOptions="/debug:pdbonly" extension=".cs" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="4">
<providerOption name="CompilerVersion" value="v3.5"/>
<providerOption name="WarnAsError" value="false"/>
</compiler><!-- removed vb.net stuff -->
</compilers>
</system.codedom>
Here's some more info on setting up compiler options in ASP.NET:
http://msdn.microsoft.com/en-us/library/a15ebt6c.aspx

Related

Why do I need to specify the compiler version on web.config to use extension methods inline?

I have an extension method on HttpRequest that I'm trying to use inline on different aspx pages.
Despite I've added the correct import to the aspx I get an error saying that the method doesn't exist. The extension method works perfect on code behind.
Compiler Error Message: CS0117: 'System.Web.HttpRequest' does not contain a definition for...
In order to fix this, I had to add this web.config declaration
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CSharp.CSharpCodeProvider,System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="4">
<providerOption name="CompilerVersion" value="v3.5"/>
<providerOption name="WarnAsError" value="false"/>
</compiler>
</compilers>
</system.codedom>
I found that here but I have no idea why I need this declaration.
I'm not sure what's for and I'm concerned that it might have some side effect.
Do you know why I need this declaration and how I could avoid it?
Extension methods were introduced in .NET 3.5. By default, inline code is compiled with CompilerVersion v2.0. You need to add the block you specified to instruct the runtime to compile language features introduced in .NET 3.5, hence the CompilerVersion value of "v3.5".
The problem is specific to ASP.NET, as extension methods compile in normal applications under the CLR 2.0 compiler.

Deploying ASP.NET application on IIS 7; got compilerVersion issue

I am trying to deploy two ASP.NET Application onto IIS 7. The first application I copied and pasted under wwwRooT folder and set Application Pool as Asp.NET 4.0 Integrated. For the second one, I created one virtual directory and set the Application Pool the same as the first application.
The first one works well, but the second one got exception:
The value for the 'compilerVersion' attribute in the provider options
must be 'v4.0' or later if you are compiling for version 4.0 or later of the .NET
Framework. To compile this Web application for version 3.5 or earlier of the .NET
Framework, remove the 'targetFramework' attribute from the element of
the Web.config file.
I had a similar problem and had to tell ASP.NET in configuration to use the 3.5 compiler as follows by modifying Web.config.
I've copied and pasted the following from my code. You have to change value="v3.5" to value="v4.0". The compiler type strings might also change.
<configuration>
<!-- ... other configuraiton stuff ... -->
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CSharp.CSharpCodeProvider,System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="4">
<providerOption name="CompilerVersion" value="v3.5"/>
<providerOption name="WarnAsError" value="false"/>
</compiler>
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="4">
<providerOption name="CompilerVersion" value="v3.5"/>
<providerOption name="OptionInfer" value="true"/>
<providerOption name="WarnAsError" value="false"/>
</compiler>
</compilers>
</system.codedom>
</configuration>
In my case the 2.0 compiler was being used instead of 3.5. I was working in an IIS 7, ASP.NET Website project.
You might glean additional insight from:
http://msdn.microsoft.com/en-us/library/system.codedom.aspx
http://msdn.microsoft.com/en-us/library/a15ebt6c%28VS.80%29.aspx

Using Trace within Global.asax

I'm struggling to output the messages written via Trace.WriteLine within the Global.asax, they don't appear in the Trace.axd.
I've added a WebPageTraceListener and a TextWriterTraceListener as documented here but all I see are the normal page events you would see in a trace which is expected.
Am I missing a step in order to get trace messages written in the Global.asax to the file/trace log? I'm doing some logging in the Application_AuthenticateRequest event.
Did you compile using the TRACE switch or update your web.config to do so automatically?
From the MSDN page you linked to (emphasis mine):
Although ASP.NET displays trace messages whenever tracing is enabled
for a page, System.Diagnostics trace messages are written only when
the code in which the trace messages reside is compiled by using an
explicit compiler switch—the TRACE switch. In other words, if you do
not explicitly compile the AuthorClass using the TRACE switch, you
will not see the trace messages, even with the WebPageTraceListener
added.
You can configure your application to automatically compile using the
TRACE switch, by adding a new section to your Web.config file.
This is the Web.config entry that should be placed after the <system.diagnostics> section:
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp"
extension=".cs"
compilerOptions="/d:TRACE"
type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="1" />
<compiler language="VB"
extension=".vb"
compilerOptions="/d:Trace=true"
type="Microsoft.VisualBasic.VBCodeProvider, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</compilers>
</system.codedom>

Asp.net v2.0 vs asp.net v3.5

I have my gui which has this in its webconfig:
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
**<providerOption name="CompilerVersion" value="v3.5"/>**
<providerOption name="WarnAsError" value="false"/>
</compiler>
</compilers>
Now when i go in the IIS and within the website properties select the asp.net version of v2.0.50727 (as i can see no higher version).. everything works fine
but now when i use another server of win 2003 i get an error
Configuration Error
Description: An error occurred during the processing of a
configuration file required to service this request. Please review the
specific error details below and modify your configuration file
appropriately.
Parser Error Message: Child nodes not allowed.
at this line:
i saw some answers which said that the server must not have v3.5... but i have selected v2.0.50727 so why do i need v3.5, also then how did it work in the previous server..
Please help..
thanks
As far as ASP.Net is concerned, 3.5 is mostly just a set of extensions for the 2.0 runtime. You still use a .Net 2.0 App Pool to run web apps built with .Net 3.5. However, you do need to make sure that .Net 3.5 is installed on the server, or the extensions won't be available.

How to specify a CompilerVersion for aspnet_compiler.exe without a web.config?

When you precompile a directory that doesn't contain a web.config, the aspnet_compiler.exe defaults to CompilerVersion 2.0 and 3.5 code fails to compile. Is the following minimal web.config the only way to specify the CompilerVersion?
<?xml version="1.0"?>
<configuration>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" warningLevel="4"
type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<providerOption name="CompilerVersion" value="v3.5"/>
<providerOption name="WarnAsError" value="false"/>
</compiler>
</compilers>
</system.codedom>
</configuration>
We integrated asp.net precompilation with our build and integration environments and don't use web.configs for our control library components
Here you can find its parameters. Also note that ASP.NET Compilation tool is not available with versions of ASP.NET earlier than ASP.NET version 2.0.
For .NET 2.0 these are the steps you need to do
Start > run and type cmd.
set path=%windir%\Microsoft.NET\Framework\v2.0.50727
aspnet_compiler –v / –p c:\myproject\testsite c:\testcompile
I think that for other versions of .NET you have to cd to corresponding directory.
Also read this. You might find it useful.

Resources