Bug in DirectCast() ?

  • Thread starter Thread starter Guido Kraus
  • Start date Start date
G

Guido Kraus

I tried this VB.NET 2003 (.Net runtime 1.1):

Dim o As Object = DirectCast(Nothing, HashTable)
If IsNothing(o) Then
Debug.WriteLine("Nothing")
Else
Debug.WriteLine("Something")
End If

Guess what: o is not Nothing!
Is this a bug or a feature? By the way: CType(Nothing, HashTable) returns
Nothing as I would expect.

Guido
 
hi Guido,

recheck your code. I tested it and cannot reproduce. I get o is Nothing.


Bill.
 
* "Guido Kraus said:
I tried this VB.NET 2003 (.Net runtime 1.1):

Dim o As Object = DirectCast(Nothing, HashTable)
If IsNothing(o) Then
Debug.WriteLine("Nothing")
Else
Debug.WriteLine("Something")
End If

Guess what: o is not Nothing!
Is this a bug or a feature? By the way: CType(Nothing, HashTable) returns
Nothing as I would expect.

I am not able to repro that in .NET 1.1, VB.NET 2003.
 
Hi Guido,

Yeh, I get the same in the watch window, but I still get the result to be
Nothing when actually run:
e.g:

Console.Writeline( DirectCast(Nothing, Hashtable) Is Nothing)

returns True.

What does your watch window say for :
DirectCast(Nothing, Hashtable) Is Nothing
 
Hi Guido,
Dim o As Object = DirectCast(Nothing, Hashtable)
Dim m As Object = CType(Nothing, Hashtable)
If m Is o Then
MessageBox.Show("both the same")
End If

both the same is showed (and they are nothing)

Cor
 
Hi Bill,

you are right.
DirectCast(Nothing, Hashtable) Is Nothing correctly returns Nothing and the
example I gave also works correctly. However, the watch window and the
variable tooltips obviously have a problem because they display {Length = 0}
instead of Nothing.

Guido
 
* "Guido Kraus said:
you are right.
DirectCast(Nothing, Hashtable) Is Nothing correctly returns Nothing and the
example I gave also works correctly. However, the watch window and the
variable tooltips obviously have a problem because they display {Length = 0}
instead of Nothing.

Yep. The watch window and the tooltips don't always show the right
data.
 
Back
Top