Description
A Razor partial view has a Model property. The Model type is specified by an @model directive.
If "Model" is used as a parameter in an ArgumentException, it raises an S3928 error message, "The parameter name 'Model' is not declared in the argument list" in SonarQube Cloud. (No error is generated by SonarAnalyzer.CSharp.)
(I expect this would also affect regular Razor pages, not just partial views, but I didn't test it, and it would be odd to have an ArgumentException on the Model in a Razor page anyway.)
Reproducer
Create an enum anywhere in your project:
public enum PassFail
{
Pass,
Fail,
}
Use that enum as the Model in a Razor partial view (e.g., "_PassFailPartial.cshtml"). Throw an ArgumentException for enum values out of range:
@model PassFail
@{
var text = Model switch
{
PassFail.Pass => "Passing",
PassFail.Fail => "Failing",
_ => throw new ArgumentOutOfRangeException(nameof(Model)),
};
}
<span>@text</span>
Product and Version
SonarQube Cloud
Description
A Razor partial view has a Model property. The Model type is specified by an
@modeldirective.If "Model" is used as a parameter in an ArgumentException, it raises an S3928 error message, "The parameter name 'Model' is not declared in the argument list" in SonarQube Cloud. (No error is generated by SonarAnalyzer.CSharp.)
(I expect this would also affect regular Razor pages, not just partial views, but I didn't test it, and it would be odd to have an ArgumentException on the Model in a Razor page anyway.)
Reproducer
Create an enum anywhere in your project:
Use that enum as the Model in a Razor partial view (e.g., "_PassFailPartial.cshtml"). Throw an ArgumentException for enum values out of range:
Product and Version
SonarQube Cloud