You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A warning that list is dereferenced when it may be null. When in fact it cannot be null because of the simple check and assignment I do.
The really interesting thing is this only shows up when targeting .NET 6 and 8 for me. .NET Standard 2.0 and 2.1 targets don't mis-fire here.
It looks like .NET 6 added [MaybeNullWhen(false)] to the TryGetValue output parameter. I bet that's what is triggering this, though it shouldn't, since I check the false condition and assign a non-null value.
The text was updated successfully, but these errors were encountered:
Thanks for looking.
In the case I got this from, I need the bool local because it is used in later expressions. So it isn't as simple as inlining it, which is what I normally do.
The current behavior is indeed "By Design". I agree it's unfortunate and it would be nice if this worked. Getting this to work though is not a trivial undertaking, it's a significant amount of design and implementation work. Rikki wrote up a summary of the problems that this poses.
Version Used: VS 17.11 Preview 1 (34828.26.main)
Steps to Reproduce:
Sharplab
Diagnostic Id: CS8602
Expected Behavior:
No warning
Actual Behavior:
A warning that
list
is dereferenced when it may be null. When in fact it cannot be null because of the simple check and assignment I do.The really interesting thing is this only shows up when targeting .NET 6 and 8 for me. .NET Standard 2.0 and 2.1 targets don't mis-fire here.
It looks like .NET 6 added
[MaybeNullWhen(false)]
to theTryGetValue
output parameter. I bet that's what is triggering this, though it shouldn't, since I check the false condition and assign a non-null value.The text was updated successfully, but these errors were encountered: