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.
| Value | |
|---|---|
| Rule ID | ASP0036 |
| Category | Usage |
| Severity | Warning |
Cause
A property on a Minimal API endpoint parameter type 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:
app.MapPost("/orders", (Order order) => Results.Ok(order));
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:
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. To opt out the whole endpoint, disable validation for the endpoint.
For more information, see Validation in ASP.NET Core.
ASP.NET Core