Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix S6964 FP: Don't raise on properties annotated with the BindRequiredAttribute #9690

Open
PaulBol opened this issue Oct 30, 2024 · 1 comment
Labels
Area: C# C# rules related issues. Type: False Positive Rule IS triggered when it shouldn't be.

Comments

@PaulBol
Copy link

PaulBol commented Oct 30, 2024

Description

S6964 complains about under-posting when properties are not nullable and annotated with BindRequiredAttribute.

Indicates that a property is required for model binding. When applied to a property, the model binding system requires a value for that property.

Repro steps

Use view model with property

[BindRequired] public int PasswordMinLength { get; init; }

Expected behavior

No issue reported.

Actual behavior

S6964 issue reported.

Known workarounds

Use required keyword in addition. Needs further code changes.

Related information

  • C#/VB.NET Plugins version: n/a
  • Visual Studio version: 2022
  • MSBuild / dotnet version: .NET 6
  • SonarScanner for .NET version (if used): 5.14 (.NET Framework)
  • Operating System: Windows 10
@sebastien-marichal
Copy link
Contributor

Hello @PaulBol,

Thank you for reporting this issue to us.

I confirm this is a false positive!

@sebastien-marichal sebastien-marichal added Type: False Positive Rule IS triggered when it shouldn't be. Area: C# C# rules related issues. labels Nov 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: C# C# rules related issues. Type: False Positive Rule IS triggered when it shouldn't be.
Projects
None yet
Development

No branches or pull requests

2 participants