dotnet / roslyn-analyzers

MIT License
1.58k stars 463 forks source link

CA1062 warning despite use of ArgumentNullException.ThrowIfNull() #7399

Open vsfeedback opened 3 weeks ago

vsfeedback commented 3 weeks ago

This issue has been moved from a ticket on Developer Community.


[severity:It bothers me. A fix would be nice] I have a Durable Function trigger method with a few input arguments, each with it's own null check guard clause.

Originally the guard clauses were using if (argument == null) { } checks but, since converting them to ArgumentNullException.ThrowIfNull(), I get a CA1062 compiler warning, despite this being the suggested alternative.

Original 2024-08-28_14-46-05 - if guard clause.png

Suggested Alternative 2024-08-28_14-47-52 - ThrowIfNull guard clauses.png

You can see the CA1062 compiler warning above, marking the variable called starter.


Original Comments

Feedback Bot on 8/29/2024, 00:28 AM:

(private comment, text removed)


Original Solutions

(no solutions)

KaineVarley commented 3 weeks ago

I reported this issue on the Visual Studio Developer Community, and they have copied it over, but I see that the image links are broken. The original message should have read:

I have a Durable Function trigger method with a few input arguments, each with it’s own null check guard clause.

Originally the guard clauses were using if (argument == null) { } checks but, since converting them to ArgumentNullException.ThrowIfNull(), I get a CA1062 compiler warning, despite this being the suggested alternative.

Original
2024-08-28_14-46-05 - if guard clause

Suggested Alternative
2024-08-28_14-47-52 - ThrowIfNull guard clauses

You can see the CA1062 compiler warning above, marking the variable called starter.