Very strange error when running debug code

  • Thread starter Thread starter TB
  • Start date Start date
T

TB

I am seeing a very strange problem as follows...

I have a loop where a fair amount of processing is going on and near
the top of the loop I access a class that has only static helper
functions to perform some calculations. After some number of
iterations, randomly, I'll get an uncaught NullValueException error on
one of these calls, as if the class name is being treated as an object
reference and is null. Here is some psuedo-code to illustrate:

Object anObject = GetNextObject();
while (anObject != null)
{
double a_value = StaticClass.CalculateA(anObject); // !!!
double b_value = StaticClass.CalculateB(anObject);

// Lots of processing

anObject = GetNextObject();
}

When I get the exception it is invariably on the first static function
call.

What is truly strange is that this problem will come and go depending
on minor, apparently unrelated changes made near the bottom of the
iteration. For example, simply inserting the statement:

int foo = 150;

where 'foo' is never actually referenced or used anywhere seems to
"fix" the problem. Wrapping the static function calls in a try-block
also seems to "fix" the problem (no exceptions are ever caught -- the
mere presence of the try-catch construct seems to cure the problem).

If I compile for release and run the code outside of the VS.NET
environment there is never any problem.

So..., I'm suspecting some problem either in the debugging code or
running debugging code in the VS.NET environment but really have no
good means to track this down any further. It's not critical since I
seem to have a work-around (I picked the try-catch as opposed to
setting 'foo' to 150 :-) I was just curious whether anyone had
encountered anything similar? Thanks!

-- TB
 
TB said:
I am seeing a very strange problem as follows...

I have a loop where a fair amount of processing is going on and near
the top of the loop I access a class that has only static helper
functions to perform some calculations. After some number of
iterations, randomly, I'll get an uncaught NullValueException error on
one of these calls, as if the class name is being treated as an object
reference and is null.
<snip>

It's not clear, but what you're describing sounds like the error is being
thrown *inside* the CalculateA method. Without seeing what CalculateA does,
it could be anything, e.g. CalculateA may be trying to dereference a null
data member of the non-null object.
 
Bret Mulvey said:
It's not clear, but what you're describing sounds like the error is being
thrown *inside* the CalculateA method. Without seeing what CalculateA does,
it could be anything, e.g. CalculateA may be trying to dereference a null
data member of the non-null object.

Apologies for not being able to supply more information, but the
actual code is too complex to supply here (not to mention most likely
considered proprietary by my employer). While it's possible the
exception is being generated somewhere inside the static function keep
in mind the following...

1) I know the object being passed into the static functions is not
null and that nothing inside the object is null -- the nature of the
iteration and the "GetNextObject" call guarantee that.

2) The static functions themselves are using this object in a
straightforward fashion and not doing anything that would try to
reference some other, null object.

3) The problem never manifests when run in release mode.

4) The problem appears to go away by the simple insertion of
completely innocuous code elsewhere in the iteration loop.

These static functions *do* serve as wrappers around procedures
imported from old, C DLLs. Perhaps something in the InteropServices
is vulnerable to this kind of weird, intermittent behavior??

A co-worker has pointed out that he observed this type of problem a
lot with the 1.0 version of C#.NET but it appeared to go away for him
when he upgraded to VS.NET 2003 (which I am also using).

-- TB
 
Back
Top