Edit

ASP0033: [ValidatableType] is applied to an inaccessible type

Value
Rule ID ASP0033
Category Usage
Severity Warning

Cause

The ValidatableTypeAttribute attribute is applied to a type that the validation source generator can't access. The type, or one of its containing types, is private or file-local.

Rule description

The validation source generator emits code in a separate file. A validatable type and all of its containing types must be public or internal and can't be file-local. Otherwise, the generator silently skips validation for the type.

The following code produces this diagnostic:

[ValidatableType]
file sealed class Asp0033FileLocalValidatableType
{
    [Required]
    public string Name { get; set; } = string.Empty;
}

How to fix violations

Make the attributed type and each of its containing types public or internal. For example, change Asp0033FileLocalValidatableType to an internal type:

[ValidatableType]
internal sealed class Asp0033FileLocalValidatableType
{
    [Required]
    public string Name { get; set; } = string.Empty;
}

For more information, see Validation in ASP.NET Core.