Reputation: 116
I have inconsistent behaviour of the VB Is Operator, as reproduced in a clean VB2012 Windows Executable project with code below. This makes it very difficult to debug some of my code, is this behaviour by design or is it a bug in VS/JIT?
Problem Sumary
At the breakpoint, Debug output show True, but Immediate Window command ?A Is B returns False
If I change ByRef to ByVal, the problem goes away
Public Sub Test()
TestInner(Nothing)
End Sub
Public Sub TestInner(ByRef A As Object)
Dim B As Object
B = New Object
A = B
Debug.WriteLine(A Is B)
'Insert breakpoint here
End Sub
I have what looks like a Compiler / Interpreter problem, has anyone seen this before?
Note that this is a simplification of my (production code) problem. If I run the exact code above, it returns True in both cases and works ok, but in my real world scenario, using fairly simple classs it fails as above.
I checked whether the classes I use have some sort of declaration problem or somehow override the Is Operator, but don't see anything weird about my classes.
I don't see how this could be anything other than a core .NET problem and am very confused!!
Upvotes: 0
Views: 86
Reputation: 239704
I would say that this is a bug, although I can't find any specific documentation about it.
The VB (and C#) expression evaluators have been extensively re-written for the VS2015 release and I would say that it's a bug in the older expression evaluator.
If we take your code and put it in a new console application in VS2015, ?A Is B
in the immediate window prints True
. If, however, we change this setting:
(Image from here)
And then repeat the experiment, we do indeed get the behaviour you've observed and it prints False
.
Upvotes: 1