Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > static constructors not always running when debugging ASP.NET sites.

Reply
Thread Tools

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

 
 
Peter Rilling
Guest
Posts: n/a
 
      11-12-2004
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?



 
Reply With Quote
 
 
 
 
Scott Allen
Guest
Posts: n/a
 
      11-13-2004
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"
<> 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?
>
>


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
reg constructors/copy constructors inheritance srp113 C++ 3 02-17-2009 04:01 PM
Is the possible to have all the public constructors of the publicbase class as the constructors of a derived class? Peng Yu C++ 5 09-19-2008 10:19 AM
compiler synthesized constructors/copy constructors/assignment operators Jess C++ 5 06-07-2007 11:09 AM
Copy constructors, de/constructors and reference counts Jeremy Smith C++ 2 08-02-2006 11:25 PM
Constructors that call other Constructors Dave Rudolf C++ 12 02-06-2004 03:26 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57