[英]Visual Studio debugger shows wrong value (null where there should be a value)
I'm stuck, why does this happen? 我被困了,为什么会这样? The code literally says that entity != null but the debugger thinks it's null.
代码字面上说实体!= null但调试器认为它是null。 What is going on?
到底是怎么回事?
I already changed to x86, recompiled, cleaned, even restarted the pc. 我已经改为x86,重新编译,清理,甚至重新启动电脑。 And the code was always like this, there is no version where the if statement was different.
并且代码总是这样,没有if语句不同的版本。 And if I continue I don't get a null-pointer exception.
如果我继续,我不会得到空指针异常。
I experienced the same problem when there was variable with same name declared earlier in the method. 当在方法中先前声明了具有相同名称的变量时,我遇到了同样的问题。 In that case debugger would only 'notice' first variable.
在这种情况下,调试器只会“注意到”第一个变量。 It has no impact on actual code execution.
它对实际代码执行没有影响。
I am not sure, but I think it is an effect of the foreach
loop in combination with the ChangeTracker.Entries()
function. 我不确定,但我认为这是
foreach
循环与ChangeTracker.Entries()
函数结合使用的ChangeTracker.Entries()
。
The foreach function is collection some data on demand. foreach函数是按需收集一些数据。 So it is not getting all the data from
ChangeTracker.Entries()
and afterwards starting the loop with each value. 因此,它不会从
ChangeTracker.Entries()
获取所有数据,然后使用每个值启动循环。
It is more getting the first value from the function --> execution the value --> getting second value --> ... 它更多地从函数中获取第一个值 - >执行值 - >获取第二个值 - > ...
So the value is null, because you haven't used the object yet. 因此该值为null,因为您尚未使用该对象。
Change your ChangeTracker.Entries()
into ChangeTracker.Entries().ToList()
and I think you will see a change. 将
ChangeTracker.Entries()
更改为ChangeTracker.Entries().ToList()
,我认为您将看到更改。
Take a look into the yield
command for an deeper understanding how the iterator function works. 查看
yield
命令以更深入地了解迭代器函数的工作原理。 (The logic is a bit confusing :) ) (逻辑有点令人困惑:))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.