468,766 Members | 1,457 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,766 developers. It's quick & easy.

Very strange error when running debug code

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
Nov 15 '05 #1
2 1451
"TB" <tb*********@kaxy.com> wrote in message
news:cd**************************@posting.google.c om...
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.
Nov 15 '05 #2
TB
"Bret Mulvey [MS]" <br***@online.microsoft.com> wrote in message news:<vFHlb.1340$275.5580@attbi_s53>...
"TB" <tb*********@kaxy.com> wrote in message
news:cd**************************@posting.google.c om...
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.


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
Nov 15 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Tony Wright | last post: by
9 posts views Thread by Abby Lee | last post: by
7 posts views Thread by p | last post: by
2 posts views Thread by Kris Vanherck | last post: by
11 posts views Thread by VijaKhara | last post: by
1 post views Thread by pitjpz | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by Marin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.