Skip to content

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

Open
@PaulBol

Description

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

Metadata

Assignees

No one assigned

    Labels

    Area: C#C# rules related issues.Type: False PositiveRule IS triggered when it shouldn't be.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions