Skip to content

Min API validation fails for Record types #61379

@mikekistler

Description

@mikekistler

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

When the input of an API is a record type, the validation endpoint filter throws an exception.


System.InvalidOperationException: Property 'EqualityContract' not found on type 'Todo'.
   at Microsoft.AspNetCore.Http.Validation.ValidatablePropertyInfo.ValidateAsync(Object value, ValidateContext context, CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Http.Validation.ValidatableTypeInfo.ValidateAsync(Object value, ValidateContext context, CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Http.Validation.ValidatableParameterInfo.ValidateAsync(Object value, ValidateContext context, CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Http.Validation.ValidationEndpointFilterFactory.<>c__DisplayClass0_0.<<Create>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Http.RequestDelegateFactory.<ExecuteValueTaskOfObject>g__ExecuteAwaited|129_0(ValueTask`1 valueTask, HttpContext httpContext, JsonTypeInfo`1 jsonTypeInfo)
   at Microsoft.AspNetCore.Http.RequestDelegateFactory.<>c__DisplayClass102_2.<<HandleRequestBodyAndCompileRequestDelegateForJson>b__2>d.MoveNext()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)

Expected Behavior

Validation should work correctly.

Steps To Reproduce

The "validation-record-types" project in this repo is a minimal repro of the problem:

https://github.com/mikekistler/dotnet10-issue-repros

The .http file contains a request that will trigger the error.

If you comment out the #define at the top of Program.cs, the project uses a class instead of a record and in this configuration the app works correctly.

Exceptions (if any)

No response

.NET Version

10.0.100-preview.3.25201.16

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-validationIssues related to model validation in minimal and controller-based APIs

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions