简体   繁体   English

Visual Studio调试器显示错误的值(null应该有值)

[英]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? 到底是怎么回事?

visual studio截图 - 调试

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.

相关问题 为什么Visual Studio调试器显示int的十六进制值很长? - Why does Visual Studio debugger shows a long hex value for an int? 在Visual Studio调试器中设置私有列表的值 - Set value of a private list in visual studio debugger 为什么Visual Studio调试器显示错误的值,我该如何纠正? - Why does the visual studio debugger show the wrong value and how can I correct this? Visual Studio调试器如何推断监视窗口内的Value? - How the Visual Studio debugger infer Value inside watch window? 如何在Visual Studio调试器中查看属性的整个值? - How can I view the entire value of a property in the Visual Studio debugger? Visual Studio - 如何在调试器中更改方法的返回值? - Visual Studio - How to change the return value of a method in the debugger? 在Visual Studio 2010调试器中修改托管代码的方法返回值 - Modifying method return value for managed code in Visual Studio 2010 debugger Aggregate显示空值 - Aggregate shows null value 为什么Visual Studio自动将数字值转换或显示为十六进制? - Why does Visual Studio automatically converts or shows a number value as hexadecimal? Visual Studio 假定 FirstOrDefaultAsync() 的返回值不能为 null - Visual Studio assumes return value from FirstOrDefaultAsync() cannot be null
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM