Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

instanciated local variable shows as null in debugging inspector

I'm encountering a strange issue when debugging some async code in visual studio: enter image description here

As you can see I have a for loop that iterates over an IEnumerable with 9 instantiated objects in it (terrible naming I know, Not my DB...) i is 0 in this case, so elementAt should put the first item in the betalingvariable. This happens correctly, and this code executes flawlessly, but in the debugger it shows as null:

enter image description here

When I continue debugging, everything is normal, the betalingvariable is used in multiple lines of code and is saved to the DB correctly, so it's only my debug inspector that shows the object as null. This is quite irritating when you are debugging however, as you can't see anything.. I suspect this has to do something with async await. There are multiple DB awaits before this loop. And the save of the betalingobject in the loop is also an await method. When I try to reproduce this behavior in a test project however, everything works fine..

I know you can have problems accessing properties from other threats in async methods, and I'm calling this code from a VM, but then why can I inspect the list? I'm suspecting this to be a bug, and if it isn't it is certainly a strange 'feature' being able to follow the lines of code but not being able to inspect some properties..

I tested this in VIsual Studio 2012 and 2013, same behavior in both.

like image 972
Arne Deruwe Avatar asked Nov 11 '22 00:11

Arne Deruwe


1 Answers

I see this on both VS 2015 Update 3 and VS 2017.

As a work-around, I found that using the mouse hover/click to 'Run execution to here' preserved the instantiated value, where the keyboard accelerator ('Ctrl+Shift+F10') would null out the instantiated value.

VS mouse hover 'Run execution to here'

like image 157
ergohack Avatar answered Nov 14 '22 21:11

ergohack