Static variables "lose" value

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I've a very strange behaveour related to a website we built:
from times to times, something should happen on the server, and all static variables inside the web application, both defined inside aspx code-behind and in business logic (C# classes used by the aspx) lose their value.

I cannot reproduce this on our development server, so I cannot understand what the cause of all this is.

We are using asp.net 1.1 with IIS6 on win2003.
 
This will happen if the app is recycled or re-booted.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

Simone Chiaretta said:
I've a very strange behaveour related to a website we built:
from times to times, something should happen on the server, and all static
variables inside the web application, both defined inside aspx code-behind
and in business logic (C# classes used by the aspx) lose their value.
 
Your orginal post stated that static variables were losing their values.
Re-starting the app doesn't restore static variables' values: It
re-initializes them.

Static variables and objects are stored in the application heap. There are
only 2 ways to change their values:

1. Programmatically: Some code in your app changes the value
2. App restart: The heap is re-built from scratch, and the static variables
are re-initialized to their beginning state.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

Simone Chiaretta said:
I don't think this is the problem, because when the problem happens what I
do to stop it and restore the original working is "recycling" the App Pool
(or making a small change to the web.config when I don't have access to the
server).
 
OK... I'm not english mother tongue, so maybe there was a mis-understanding :-)

In my application static var are used to store values (objects) that are read during the startup from the DB.
When I said that "restore static variables' values" I meant that they are reinitialized

What I've is that when something happens, then all lines of code that access to any static variable throws a "System.NullReferenceException - Object reference not set to an instance of an object"
 
OK... I'm not english mother tongue, so maybe there was a mis-understanding :-)

In my application static var are used to store values (objects) that are read during the startup from the DB.
When I said that "restore static variables' values" I meant that they are reinitialized

What I've is that when something happens, then all lines of code that access to any static variable throws a "System.NullReferenceException - Object reference not set to an instance of an object"
 
In order to help you, I will need more exact information. You said that your
static variables "are used to store values (objects) that are read during
the startup from the DB." I need to know:

1. Where are they stored?
2. How are they fetched from the DB (what event handler loads them)?
3. What "something" happens to cause the error?

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.


Simone Chiaretta said:
OK... I'm not english mother tongue, so maybe there was a mis-understanding :-)

In my application static var are used to store values (objects) that are
read during the startup from the DB.
When I said that "restore static variables' values" I meant that they are reinitialized

What I've is that when something happens, then all lines of code that
access to any static variable throws a "System.NullReferenceException -
Object reference not set to an instance of an object"
 
BTW, patience is a virtue. If the message form doesn't submit immediately,
you might want to give it a little time before you re-submit your form - 15
times. ;-)

--
Ciao,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

Simone Chiaretta said:
OK... I'm not english mother tongue, so maybe there was a mis-understanding :-)

In my application static var are used to store values (objects) that are
read during the startup from the DB.
When I said that "restore static variables values" I meant that they are reinitialized

What I've is that when something happens, then all lines of code that
access to any static variable throws a "System.NullReferenceException -
Object reference not set to an instance of an object"
 
The problem arise mainly in one object...
1 - it's a static variable inside the global.asax
2 - it's populated in the Application_onStart and nowhere else set

3 - The "something" is an unspecified event I cannot track back (a memory
leack? a bug inside .NET framework? whatever?) that cause the static variable
to become "null"
 
Hi Simone,
1 - it's a static variable inside the global.asax

When you say "it's a static variable inside the global.asax" what exactly do
you mean? global.asax is a file that is compiled into a class. Is it a field
in the class? Is it a property? What exactly?

How is it populated? What kind of data is in it?

A variable doesn't just become null all by itself. Something has to change
it. Something has to set its value, and something has to make it null. It
would be really good if you could track down the event that is causing this
to happen, at least narrow the time down. Perhaps posting the code that
creates the variable would help also.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
Back
Top