Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
ASP0035: Validatable property or its type on a
| Value | |
|---|---|
| Rule ID | ASP0035 |
| Category | Usage |
| Severity | Warning |
Cause
A property on a type marked with ValidatableTypeAttribute declares validation, but the property, its getter, or its type isn't accessible to the validation source generator.
Rule description
The validation source generator can only generate validation for public properties with public getters and accessible property types. An inaccessible property that has validation attributes, implements IValidatableObject, or contains a type that declares validation is silently skipped.
The following code produces this diagnostic because Child isn't public:
[ValidatableType]
public class Order
{
internal Customer Child { get; } = new();
public class Customer
{
[Required]
public string? Name { get; set; }
}
}
How to fix violations
Make the property and its getter public. Also make the property type and each of its containing types public or internal and don't declare them as file-local:
[ValidatableType]
public class Order
{
public Customer Child { get; } = new();
public class Customer
{
[Required]
public string? Name { get; set; }
}
}
If the property shouldn't be validated, apply SkipValidationAttribute to it.
For more information, see Validation in ASP.NET Core.
ASP.NET Core