CLR bug?

J

Jesper, Denmark

Preamble.
Back in the .net 1.0 days I was very concerned about a CLR bug that I
encountered. I had an if-then-else clause and the thread did not enter either
the true or false statements. After an upgrade to .net 1.1 (suggested by
Microsoft that recognized this erroneous behaviour) the problem were
resolved. Howver, as it was the first time ever I had expericed a
compiler/I.L. execution (whatever??) error, I lost a little confidence in the
compilation/i.l execution in .net. As a former c++ programmer I had learned
by experience that I, as the programmer, always were the origin of unexpected
behaviour - but this experience changed that - and today, a new weird thing
is happening. Please help:


foreach (ListViewItem lvi in this.listViewToDoList.Items)
{
Work wp = (Work)lvi.Tag;
lvi.ImageIndex = GetWaypointImageIndex(wp);
lvi.Checked = wp.Done;
lvi.SubItems[2].Text = wp.Modified;
}

The weird thing is that the collection only contains 2 elements!, the Count
field is equal to 2. But it runs thru the loop a third time and throws an
exception that lvi is null!?!. How is that possible?

Best regards
Jesper
 
J

Jon Skeet [C# MVP]

Preamble.
Back in the .net 1.0 days I was very concerned about a CLR bug that I
encountered. I had an if-then-else clause and the thread did not enter either
the true or false statements. After an upgrade to .net 1.1 (suggested by
Microsoft that recognized this erroneous behaviour) the problem were
resolved. Howver, as it was the first time ever I had expericed a
compiler/I.L. execution (whatever??) error, I lost a little confidence in the
compilation/i.l execution in .net. As a former c++ programmer I had learned
by experience that I, as the programmer, always were the origin of unexpected
behaviour

You never, ever ran into a compiler or library bug? You're lucky :)
- but this experience changed that - and today, a new weird thing
is happening. Please help:

foreach (ListViewItem lvi in this.listViewToDoList.Items)
{
Work wp = (Work)lvi.Tag;
lvi.ImageIndex = GetWaypointImageIndex(wp);
lvi.Checked = wp.Done;
lvi.SubItems[2].Text = wp.Modified;
}

The weird thing is that the collection only contains 2 elements!, the Count
field is equal to 2. But it runs thru the loop a third time and throws an
exception that lvi is null!?!. How is that possible?

Pretty hard to say without a way of reproducing it (although I think
it's more likely to be a framework bug than a CLR bug, if indeed
there's a bug at all).

Could you post a short but complete program which demonstrates the
problem?

See http://pobox.com/~skeet/csharp/complete.html for what I mean by
that.

Jon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top