|
| 1 | +--- |
| 2 | +title: "ASP0036: Validatable property or its type on an endpoint parameter type is not accessible" |
| 3 | +description: "Learn about analysis rule ASP0036: A validatable property or its type on an endpoint parameter type isn't accessible." |
| 4 | +monikerRange: '>= aspnetcore-11.0' |
| 5 | +ms.date: 08/25/2026 |
| 6 | +author: snemeckayova |
| 7 | +ms.author: snemeckayova |
| 8 | +uid: diagnostics/asp0036 |
| 9 | +--- |
| 10 | +# ASP0036: Validatable property or its type on an endpoint parameter type is not accessible |
| 11 | + |
| 12 | +| | Value | |
| 13 | +| - | - | |
| 14 | +| **Rule ID** | ASP0036 | |
| 15 | +| **Category** | Usage | |
| 16 | +| **Severity** | Warning | |
| 17 | + |
| 18 | +## Cause |
| 19 | + |
| 20 | +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. |
| 21 | + |
| 22 | +## Rule description |
| 23 | + |
| 24 | +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. |
| 25 | + |
| 26 | +The following code produces this diagnostic because `Child` isn't public: |
| 27 | + |
| 28 | +```csharp |
| 29 | +app.MapPost("/orders", (Order order) => Results.Ok(order)); |
| 30 | + |
| 31 | +public class Order |
| 32 | +{ |
| 33 | + internal Customer Child { get; } = new(); |
| 34 | + |
| 35 | + public class Customer |
| 36 | + { |
| 37 | + [Required] |
| 38 | + public string? Name { get; set; } |
| 39 | + } |
| 40 | +} |
| 41 | +``` |
| 42 | + |
| 43 | +## How to fix violations |
| 44 | + |
| 45 | +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: |
| 46 | + |
| 47 | +```csharp |
| 48 | +public class Order |
| 49 | +{ |
| 50 | + public Customer Child { get; } = new(); |
| 51 | + |
| 52 | + public class Customer |
| 53 | + { |
| 54 | + [Required] |
| 55 | + public string? Name { get; set; } |
| 56 | + } |
| 57 | +} |
| 58 | +``` |
| 59 | + |
| 60 | +If the property shouldn't be validated, apply <xref:Microsoft.Extensions.Validation.SkipValidationAttribute> to it. To opt out the whole endpoint, disable validation for the endpoint. |
| 61 | + |
| 62 | +For more information, see <xref:fundamentals/validation>. |
0 commit comments