Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between IsDebuggingEnabled and Debugger.IsAttached

Tags:

c#

.net

asp.net

Are there any differences between System.Web.HttpContext.Current.IsDebuggingEnabled and System.Diagnostics.Debugger.IsAttached?

If so, what are the exact differences besides the fact that one is only for web applications while the other works in all kind of projects?

like image 837
Martin Braun Avatar asked Sep 03 '14 07:09

Martin Braun


People also ask

What is debugger IsAttached?

Debugger. IsAttached is a runtime check, so the debugging code still gets included in the assembly, but only executes if a debugger is attached to the process.

How do I know if debugger is attached?

Kernel-mode code can determine the status of kernel debugging by using the following variables and routines: The KD_DEBUGGER_ENABLED global kernel variable indicates whether kernel debugging is enabled. The KD_DEBUGGER_NOT_PRESENT global kernel variable indicates whether a kernel debugger is currently attached.


2 Answers

HttpContext.IsDebuggingEnabled is about the compilation setting in the web.config. Debugger.IsAttached defines if there is actually an active debugger listening to the information coming from the web server.

See the explanation at DotnetPerls regarding HttpContext.IsDebuggingEnabled:

Debug mode is not the default. ... When you do not set debug="true" in Web.config, the site is compiled in Release mode.

Regarding your question why the first 'one is only for web applications': web applications have the ability to compile at run-time, while all other .NET products are pre-compiled. Because of this, you can define in the web.config if the build is done in Debug or Release mode. This is a ASP.NET only option, so the property is only available there.

As answer to your second question, why the first option is only for ASP.NET: There is also a way for a Windows application to check it's build status: by checking the DebuggableAttribute as explained in How to check if an assembly was built using Debug or Release configuration?.

like image 51
Patrick Hofman Avatar answered Oct 08 '22 12:10

Patrick Hofman


IsDebuggingEnabled refers to "debug mode" which does not necessarily mean a debugger is actually attached. You can set ASP.NET websites into debug mode by setting <compilation debug="true"> in your web.config file.

When a website is in debug mode, JIT optimizations are not applied to code contained within your view files (.aspx, .cshtml, etc) as well as any runtime-compiled code-behind files or the App_Code directory. There are also other effects.

like image 40
Dai Avatar answered Oct 08 '22 13:10

Dai