I'm unable to get CA1062 (validate arguments of public methods) to evaluate.
I've created a .Net Standard 2.0 C# class library and installed Microsoft.CodeQuality.Analyzers
and several others nuget packages as per this screenshot:
I've also enabled CA1062 in the ruleset for the project, as per the image:
I've created this class to test if CA1062 (validate arguments of public methods) does evaluate:
public class Person
{
public String Name { get; }
public Person(String name)
{
this.Name = name;
}
public void DeclareWarOn(Person enemy)
{
String enemyName = enemy.Name;
Console.WriteLine($"{this.Name} declared war on {enemyName}");
}
}
In the DeclareWarOn
method the parameter enemy
is never checked for a null
value but is used in the line String enemyName = enemy.Name;
This is suppose to trigger CA1062, but it is not triggered.
Other rules do evaluate. As example, I have created an internal
Exception class as such:
internal class MyException : Exception
{
...
}
And this did indeed trigger the relevant code analysis warning for it (CA1064). However I can't get CA1062 to evaluate.
I've recently removed all Analyzers and installed a higher version of the FxCop package on this project, and it solved the issue.
(I've added this in case any developer discovers this post and is still searching for a solution)