CA1062 not evaluating on .Net Standard 2.0 class library
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
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.
c# visual-studio-2017 code-analysis ca1062
add a comment |
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.
c# visual-studio-2017 code-analysis ca1062
1
at first I though along the line of "could it be smart enough to detect that there is no default constructor, and no instance ofPersoncould ever be constructed without a name", but you can still callDeclareWarOn(null);so that would be a bug of the analyzer.
– dlatikay
Nov 23 '18 at 14:28
1
Found any solution yet ? got the same problem here. The same goes for CA1031 and CA1047. But others like CA1063, CA1716, CA1816 are detected correctly. I don't understand why some rules work and others don't.
– Jonathan
Jan 21 at 14:38
Unfortunately not. I also have a lot of other CA rules not evaluating correctly, even despite setting each rule to evaluate as an error.
– Cornelius
Jan 21 at 15:45
add a comment |
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.
c# visual-studio-2017 code-analysis ca1062
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.
c# visual-studio-2017 code-analysis ca1062
c# visual-studio-2017 code-analysis ca1062
asked Nov 23 '18 at 14:23
CorneliusCornelius
2,14552447
2,14552447
1
at first I though along the line of "could it be smart enough to detect that there is no default constructor, and no instance ofPersoncould ever be constructed without a name", but you can still callDeclareWarOn(null);so that would be a bug of the analyzer.
– dlatikay
Nov 23 '18 at 14:28
1
Found any solution yet ? got the same problem here. The same goes for CA1031 and CA1047. But others like CA1063, CA1716, CA1816 are detected correctly. I don't understand why some rules work and others don't.
– Jonathan
Jan 21 at 14:38
Unfortunately not. I also have a lot of other CA rules not evaluating correctly, even despite setting each rule to evaluate as an error.
– Cornelius
Jan 21 at 15:45
add a comment |
1
at first I though along the line of "could it be smart enough to detect that there is no default constructor, and no instance ofPersoncould ever be constructed without a name", but you can still callDeclareWarOn(null);so that would be a bug of the analyzer.
– dlatikay
Nov 23 '18 at 14:28
1
Found any solution yet ? got the same problem here. The same goes for CA1031 and CA1047. But others like CA1063, CA1716, CA1816 are detected correctly. I don't understand why some rules work and others don't.
– Jonathan
Jan 21 at 14:38
Unfortunately not. I also have a lot of other CA rules not evaluating correctly, even despite setting each rule to evaluate as an error.
– Cornelius
Jan 21 at 15:45
1
1
at first I though along the line of "could it be smart enough to detect that there is no default constructor, and no instance of
Person could ever be constructed without a name", but you can still call DeclareWarOn(null); so that would be a bug of the analyzer.– dlatikay
Nov 23 '18 at 14:28
at first I though along the line of "could it be smart enough to detect that there is no default constructor, and no instance of
Person could ever be constructed without a name", but you can still call DeclareWarOn(null); so that would be a bug of the analyzer.– dlatikay
Nov 23 '18 at 14:28
1
1
Found any solution yet ? got the same problem here. The same goes for CA1031 and CA1047. But others like CA1063, CA1716, CA1816 are detected correctly. I don't understand why some rules work and others don't.
– Jonathan
Jan 21 at 14:38
Found any solution yet ? got the same problem here. The same goes for CA1031 and CA1047. But others like CA1063, CA1716, CA1816 are detected correctly. I don't understand why some rules work and others don't.
– Jonathan
Jan 21 at 14:38
Unfortunately not. I also have a lot of other CA rules not evaluating correctly, even despite setting each rule to evaluate as an error.
– Cornelius
Jan 21 at 15:45
Unfortunately not. I also have a lot of other CA rules not evaluating correctly, even despite setting each rule to evaluate as an error.
– Cornelius
Jan 21 at 15:45
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53448427%2fca1062-not-evaluating-on-net-standard-2-0-class-library%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53448427%2fca1062-not-evaluating-on-net-standard-2-0-class-library%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
at first I though along the line of "could it be smart enough to detect that there is no default constructor, and no instance of
Personcould ever be constructed without a name", but you can still callDeclareWarOn(null);so that would be a bug of the analyzer.– dlatikay
Nov 23 '18 at 14:28
1
Found any solution yet ? got the same problem here. The same goes for CA1031 and CA1047. But others like CA1063, CA1716, CA1816 are detected correctly. I don't understand why some rules work and others don't.
– Jonathan
Jan 21 at 14:38
Unfortunately not. I also have a lot of other CA rules not evaluating correctly, even despite setting each rule to evaluate as an error.
– Cornelius
Jan 21 at 15:45