By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,695 Members | 1,348 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,695 IT Pros & Developers. It's quick & easy.

Static variables "lose" value

P: n/a
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.

Nov 18 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
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" <Si*************@discussions.microsoft.com> wrote in
message news:E5**********************************@microsof t.com...
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.

Nov 18 '05 #2

P: n/a
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" <Si*************@discussions.microsoft.com> wrote in
message news:45**********************************@microsof t.com...
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).
Simone

"Kevin Spencer" wrote:
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" <Si*************@discussions.microsoft.com> wrote in
message news:E5**********************************@microsof t.com...
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.


Nov 18 '05 #3

P: n/a
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"

--
Simone Chiaretta
Milan, Italy
..Net Web Developer
"Kevin Spencer" wrote:
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" <Si*************@discussions.microsoft.com> wrote in
message news:45**********************************@microsof t.com...
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).

Simone

"Kevin Spencer" wrote:
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" <Si*************@discussions.microsoft.com> wrote in
message news:E5**********************************@microsof t.com...
> 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.
>


Nov 18 '05 #4

P: n/a
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"

--
Simone Chiaretta
Milan, Italy
..Net Web Developer
"Kevin Spencer" wrote:
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" <Si*************@discussions.microsoft.com> wrote in
message news:45**********************************@microsof t.com...
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).

Simone

"Kevin Spencer" wrote:
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" <Si*************@discussions.microsoft.com> wrote in
message news:E5**********************************@microsof t.com...
> 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.
>


Nov 18 '05 #5

P: n/a
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" <Si*************@discussions.microsoft.com> wrote in
message news:F7**********************************@microsof t.com...
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"
--
Simone Chiaretta
Milan, Italy
.Net Web Developer
"Kevin Spencer" wrote:
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" <Si*************@discussions.microsoft.com> wrote in
message news:45**********************************@microsof t.com...
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).

Simone

"Kevin Spencer" wrote:

> 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" <Si*************@discussions.microsoft.com> wrote
in > message news:E5**********************************@microsof t.com...
> > 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.
> >
>
>
>


Nov 18 '05 #6

P: n/a
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" <Si*************@discussions.microsoft.com> wrote in
message news:90**********************************@microsof t.com...
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"

--
Simone Chiaretta
Milan, Italy
.Net Web Developer
"Kevin Spencer" wrote:
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" <Si*************@discussions.microsoft.com> wrote in
message news:45**********************************@microsof t.com...
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).

Simone

"Kevin Spencer" wrote:

> 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" <Si*************@discussions.microsoft.com> wrote
in > message news:E5**********************************@microsof t.com...
> > 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.
> >
>
>
>


Nov 18 '05 #7

P: n/a
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"

"Kevin Spencer" wrote:
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" <Si*************@discussions.microsoft.com> wrote in
message news:F7**********************************@microsof t.com...
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"

--
Simone Chiaretta
Milan, Italy
.Net Web Developer
"Kevin Spencer" wrote:
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" <Si*************@discussions.microsoft.com> wrote in
message news:45**********************************@microsof t.com...
> 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).
>
> Simone
>
> "Kevin Spencer" wrote:
>
> > 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" <Si*************@discussions.microsoft.com> wrote in > > message news:E5**********************************@microsof t.com...
> > > 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.
> > >
> >
> >
> >


Nov 18 '05 #8

P: n/a
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.

"Simone Chiaretta" <Si*************@discussions.microsoft.com> wrote in
message news:50**********************************@microsof t.com... 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"

"Kevin Spencer" wrote:
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" <Si*************@discussions.microsoft.com> wrote in
message news:F7**********************************@microsof t.com...
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"

--
Simone Chiaretta
Milan, Italy
.Net Web Developer
"Kevin Spencer" wrote:

> 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" <Si*************@discussions.microsoft.com> wrote
in > message news:45**********************************@microsof t.com...
> > 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).
> >
> > Simone
> >
> > "Kevin Spencer" wrote:
> >
> > > 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" <Si*************@discussions.microsoft.com>
wrote in
> > > message
news:E5**********************************@microsof t.com... > > > > 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.
> > > >
> > >
> > >
> > >
>
>
>


Nov 18 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.