instanciated local variable shows as null in debugging inspector

本小妞迷上赌 提交于 2019-12-10 17:14:09

问题


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

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:

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.


回答1:


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.



来源:https://stackoverflow.com/questions/26502128/instanciated-local-variable-shows-as-null-in-debugging-inspector

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!