MemberNotNullWhenAttribute completely ignored for async methods #6564
Replies: 3 comments 5 replies
-
I assume this is because the method doesn't ever return I imagine you could write an analyser yourself that detects whether you are using that attribute on a method that can't return |
Beta Was this translation helpful? Give feedback.
-
Duplicate of #5657. |
Beta Was this translation helpful? Give feedback.
-
It should be pointed out that Intellisense thinks the [MemberNotNullWhen(true, nameof(Data))]
public async bool ReadAsync()
{
Data = await ReadDataAsync();
return true;
} I will get a warning:
So it appears that the fact this attribute has no effect with async methods is something that just hasn't been looked at or considered. Unfortunately, I see no good workaround for this issue. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have code similar to the following.
This works great. But now I want to add an
async
version of this method.This compiles just fine and gives no warnings. But the
MemberNotNullWhenAttribute
is completely ignored. UsingData
after this method returns true still gives the warning that it could be null.This is for a NuGet package so eliminating that warning is pretty important. Is there no way to support this? Is there a workaround? Is a change needed to this attribute? Is a new attribute needed? I would settle for
MemberNotNullAttribute
working here.At the very least, I think the compiler should issue some warning that the
MemberNotNullWhenAttribute
is going to be ignored.Beta Was this translation helpful? Give feedback.
All reactions