Is there an existing issue for this?
Describe the bug
With data annotation based validation enabled in minimal APIs, the validation subsystem throws an unhandled exception if it encounters a request that is a JsonElement or JsonDocument or is a type that contains a public property with one of those types.
fail: Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware[1]
An unhandled exception has occurred while executing the request.
System.InvalidOperationException: Property 'this[]' not found on type 'JsonElement'.
https://learn.microsoft.com/en-us/aspnet/core/release-notes/aspnetcore-10.0?view=aspnetcore-10.0#validation-support-in-minimal-apis
Expected Behavior
I expect these types to be acceptable, as is, I need to change the request or request property type to string or maybe BinaryData and perform serialization in the endpoint handler or accept the raw HttpRequest.Body stream.
Steps To Reproduce
builder.Services.AddValidation();
app.MapPost("/test", ([FromBody] JsonElement request) =>
{
// ...
});
Exceptions (if any)
fail: Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware[1]
An unhandled exception has occurred while executing the request.
System.InvalidOperationException: Property 'this[]' not found on type 'JsonElement'.
at Microsoft.Extensions.Validation.ValidatablePropertyInfo.ValidateAsync(Object value, ValidateContext context, CancellationToken cancellationToken)
at Microsoft.Extensions.Validation.ValidatableTypeInfo.ValidateMembersAsync(Object value, ValidateContext context, CancellationToken cancellationToken)
at Microsoft.Extensions.Validation.ValidatableTypeInfo.ValidateAsync(Object value, ValidateContext context, CancellationToken cancellationToken)
at Microsoft.Extensions.Validation.ValidatablePropertyInfo.ValidateAsync(Object value, ValidateContext context, CancellationToken cancellationToken)
at Microsoft.Extensions.Validation.ValidatableTypeInfo.ValidateMembersAsync(Object value, ValidateContext context, CancellationToken cancellationToken)
at Microsoft.Extensions.Validation.ValidatableTypeInfo.ValidateAsync(Object value, ValidateContext context, CancellationToken cancellationToken)
at Microsoft.Extensions.Validation.ValidatablePropertyInfo.ValidateAsync(Object value, ValidateContext context, CancellationToken cancellationToken)
at Microsoft.Extensions.Validation.ValidatableTypeInfo.ValidateMembersAsync(Object value, ValidateContext context, CancellationToken cancellationToken)
at Microsoft.Extensions.Validation.ValidatableTypeInfo.ValidateAsync(Object value, ValidateContext context, CancellationToken cancellationToken)
at Microsoft.Extensions.Validation.ValidatableParameterInfo.ValidateAsync(Object value, ValidateContext context, CancellationToken cancellationToken)
at Microsoft.AspNetCore.Http.Validation.ValidationEndpointFilterFactory.<>c__DisplayClass1_0.<<Create>b__0>d.MoveNext()
--- End of stack trace from previous location ---
.NET Version
.NET 10
Is there an existing issue for this?
Describe the bug
With data annotation based validation enabled in minimal APIs, the validation subsystem throws an unhandled exception if it encounters a request that is a
JsonElementorJsonDocumentor is a type that contains a public property with one of those types.https://learn.microsoft.com/en-us/aspnet/core/release-notes/aspnetcore-10.0?view=aspnetcore-10.0#validation-support-in-minimal-apis
Expected Behavior
I expect these types to be acceptable, as is, I need to change the request or request property type to
stringor maybeBinaryDataand perform serialization in the endpoint handler or accept the rawHttpRequest.Bodystream.Steps To Reproduce
Exceptions (if any)
.NET Version
.NET 10