This is a debugger bug. The behavior that is evident in the screenshot is impossible under the C# language spec.
This could be a CLR bug but that is highly unlikely. if
does not have bugs.
Create a small, executable repro and report it on MS Connect.
You can add an assertion rule == null
in the if
statement body and it will not fire. That proves that the value is actually null
as expected.
As a funny yet unlikely alternative theory there could be an overloaded and broken operator equals.
In my experience debugger bugs are not rare. I have found a few over the years. Nothing too serious. The debugger is a very complicated piece of machinery that inspects running programs in a very invasive way. Hard to get that 100% right.
The only explanation (outside of an unlikely bug in VS) is that the source version does not match the compiled version (compiled version = debug symbols). This is possible using this setting in Visual Studio.
Debug (menu) -> Options (menu item) -> Debugging (tab) -> General -> "Require source files to exactly match the original version"
If you had if(rule != null)
before and all you did was change it to if(rule == null)
in the code but the debug symbols did not update then this could explain the behavior on screen.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.