Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QuickWatch is not work correctly for show ".ToString()" of Nullable properties

I have a nullable integer property in vb.net.
This property in code has correct value, but in the QuickWatch always display 1, unless I initial it by a value then display a six digitalis numbers.

My codes is:

Public Property MyNumber As Integer?

MyNumber = 6546

MessageBox.Show(MyNumber.ToString())

QuickWatch1

And for nullable double property in QuickWatch always display 4/94065645841247E-324.

QuickWatch2

I test this on .Net 4 & 4.5 on visual studio 2010 & 2013 and get same result. However C# hasn't this problem

EDIT:

I append my project result too, as you see in watch windows both of them is shown QuickWatch3

Why this happens ?

EDIT:

This problem is with .Net 4 and 4.5 and 4.5.1. With .Net 2.0 and 3.5 has no problem

like image 373
Behzad Avatar asked Jul 09 '15 08:07

Behzad


1 Answers

Confirmed, this is indeed a bug in the debugger. I searched connect.microsoft.com and could not find anything similar, this is not a bug that strikes many VB.NET programmers. Not entirely surprising, this only goes wrong when you append .ToString() to the nullable variable name. Nobody ever does that.

It is not the kind of bug you can get any help with at this site, it is a bug that Microsoft needs to fix.

Characterizing the bug a bit, this appears to go wrong in the VB.NET specific expression parser built into the debugger. The reason that you can't repro this in a C# project. And why the bitness of the process doesn't matter, the 64-bit debugger also shows bad values. This is in general a fickle piece of code that Microsoft has been working on to retire. Basic problem is that they had to build the equivalent of the VB.NET compiler into the debugger so that these expressions could be parsed. Limited though, that parser does not nearly support the entire language. Side-effect is that the code that debugger runs can be different than the code your program runs.

The code-generation for Nullable(Of T).ToString() is fairly tricky, it requires a conditional boxing conversion. The parser flubs it for any such expression, note how MyNumber.GetHashCode() produces the wrong value as well. And MyNumber.Equals(5456.0). The kind of expressions that require that boxing conversion.

You can technically report this bug at connect.microsoft.com as well but I would not recommend spending the time. As noted, Microsoft has been working on retiring this parser and that finally happened. Powered by Roslyn, a compile service that's usable anywhere. It was integrated into VS2015 and as far as know the debugger uses it as well. Not 100% sure, I'll know in 9 days when VS2015 is released. Maybe somebody that has the beta/RC edition installed can confirm with a comment.

UPDATE: confirmed fixed on VS2015.

Meanwhile, until you can update, the workaround is to just stop using ToString() on nullable variables in your quick/watch expressions. It is buggy.

like image 98
Hans Passant Avatar answered Nov 09 '22 23:11

Hans Passant