473,322 Members | 1,496 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

static constructors not always running when debugging ASP.NET sites.

Here is a weird behavior that I would not have expected in VS.NET during
debugging. Maybe someone has some insight as to why this is happening.

1) I have a VS.NET web project. This contains a class with a static
constructor.
2) The static constructor loads custom information from the web.config.
3) First time I debug, everything works fine. I hit the breakpoint in the
static constructor.
4) I stop debugging. At this point I would have expected all objects to be
removed from memory.
5) I start debugging again. This time I do not hit the static constructor.
6) I make a change in the web.config file.
7) I start debugging again. This time the static constructor does run.

Why might this be happening? I would have thought that each time I run the
debugger, it would be starting a new process which would have new variables.
Static variables I thought were confined to the process in which it is
running in. Another related question might be, what is the scope and
lifetime of a static object in an ASP.NET world?

Nov 18 '05 #1
1 2017
Hi Peter:

Are you using attach / detach process during debugging?

Changing web.config will definitely force the web application to
reload and re-execute static ctors.

Static variables are scoped to an application domain. There can be
more than one app domain in a process, which is how asp.net can host
mutliple web applications inside a single worker process - each app
gets it's own app domain, and the statics do not interfere with each
other. A static ctor is guaranteed to run no more than once for an app
domain.

If you keep a reference to an object in a static field it will be
there for the life of the app domain (unless you overwrite or null out
the field).

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Fri, 12 Nov 2004 14:44:11 -0800, "Peter Rilling"
<pe***@nospam.rilling.net> wrote:
Here is a weird behavior that I would not have expected in VS.NET during
debugging. Maybe someone has some insight as to why this is happening.

1) I have a VS.NET web project. This contains a class with a static
constructor.
2) The static constructor loads custom information from the web.config.
3) First time I debug, everything works fine. I hit the breakpoint in the
static constructor.
4) I stop debugging. At this point I would have expected all objects to be
removed from memory.
5) I start debugging again. This time I do not hit the static constructor.
6) I make a change in the web.config file.
7) I start debugging again. This time the static constructor does run.

Why might this be happening? I would have thought that each time I run the
debugger, it would be starting a new process which would have new variables.
Static variables I thought were confined to the process in which it is
running in. Another related question might be, what is the scope and
lifetime of a static object in an ASP.NET world?


Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Tim | last post by:
Please advise if you can. Presumably initialisation of members in member initialisation lists is perfomed by 'C' run-time startup. If the CRT was never started-up would those members be garbage?...
4
by: Steve | last post by:
I'm currently running into a problem, and I have no idea what to make of it. I have a class with nested clases and static properties that I'm using to store configuration information using a...
12
by: Joe Narissi | last post by:
I know how to create and use static constructors, but is there a such thing as a static destructor? If not, then how do you deallocate memory intialized in the static constructor? Thanks in...
14
by: Jeroen | last post by:
Hi all, I've got a question about writing a library. Let me characterize that library by the following: * there is a class A which is available to the user * there is a class B that is used...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.