V
Vagif Abilov
We have several Web projects where we suddenly began experiencing various
problems after porting them to .NET 2.0. I debugged one of them and here's
what I've found:
In one of referenced assemblies there was a class with static members of
other class:
class A
{
...
static B b;
void Init()
{
if(b != null)
{
b = new B();
}
}
}
The problem was related to "b" instance, so I ran a debugger session and
discovered that I never entered code "b = new B()". The member variable "b"
has always been instantiated when I checked its value in debug session!
Then I slightly modified the code:
class A
{
...
static B b = null;
void Init()
{
if(b != null)
{
b = new B();
}
}
}
Then everything worked. But why? If we have a reference type, why does it
make any difference if we instantiate the variable of this type to null or
not? It shouldn't! Reference types instances must be set to null.
I also tried to run this code in non-Web project, but there it worked
without any problem. It has to be something related to ASP.NET.
Any info on this issue is appreciated.
Vagif Abilov
Oslo Norway
problems after porting them to .NET 2.0. I debugged one of them and here's
what I've found:
In one of referenced assemblies there was a class with static members of
other class:
class A
{
...
static B b;
void Init()
{
if(b != null)
{
b = new B();
}
}
}
The problem was related to "b" instance, so I ran a debugger session and
discovered that I never entered code "b = new B()". The member variable "b"
has always been instantiated when I checked its value in debug session!
Then I slightly modified the code:
class A
{
...
static B b = null;
void Init()
{
if(b != null)
{
b = new B();
}
}
}
Then everything worked. But why? If we have a reference type, why does it
make any difference if we instantiate the variable of this type to null or
not? It shouldn't! Reference types instances must be set to null.
I also tried to run this code in non-Web project, but there it worked
without any problem. It has to be something related to ASP.NET.
Any info on this issue is appreciated.
Vagif Abilov
Oslo Norway