Skip to content

Minimal API Validation throws exception for endpoint that accepts JsonPatchDocument #63047

@mikekistler

Description

@mikekistler

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

I have a patch endpoint that accepts the new JsonPatchDocument for System.Text.Json added in .NET 10. When I call this endpoint with Minimal API validation enabled, it throws an exception:

fail: Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware[1]
66
      An unhandled exception has occurred while executing the request.
67
      System.InvalidOperationException: Maximum validation depth of 32 exceeded at 'SerializerOptions.Default.Default.Default.Default.Default.Default.Default.Default.Default.Default.Default.Default.Default.Default.Default.Default.Default.Default.Default.Default.Default.Default.Default.Default.Default.Default.Default.Default.Default.Default.Default' in 'JsonSerializerOptions'. This is likely caused by a circular reference in the object graph. Consider increasing the MaxDepth in ValidationOptions if deeper validation is required.
68
         at Microsoft.Extensions.Validation.ValidatableTypeInfo.ValidateAsync(Object value, ValidateContext context, CancellationToken cancellationToken)
69
         at Microsoft.Extensions.Validation.ValidatablePropertyInfo.ValidateAsync(Object value, ValidateContext context, CancellationToken cancellationToken)
70
         at Microsoft.Extensions.Validation.ValidatableTypeInfo.ValidateAsync(Object value, ValidateContext context, CancellationToken cancellationToken)
71
         at Microsoft.Extensions.Validation.ValidatablePropertyInfo.ValidateAsync(Object value, ValidateContext context, CancellationToken cancellationToken)
72
         at Microsoft.Extensions.Validation.ValidatableTypeInfo.ValidateAsync(Object value, ValidateContext context, CancellationToken cancellationToken)

Expected Behavior

Min API validation should not throw for JsonPatchDocument.

Steps To Reproduce

Here's the definition of the endpoint that exhibits the bug:

    public static async Task<Results<Ok<CatalogItem>, ValidationProblem, NotFound<ProblemDetails>>> UpdateItem(
        HttpRequest httpRequest,
        [AsParameters] CatalogServices services,
        int id,
        JsonPatchDocument<CatalogItem> patchDoc
    )

where:

public class CatalogServices(
    // CatalogContext context,
    ILogger<CatalogServices> logger
)
{
    // [FromServices]
    // public CatalogContext Context { get; } = context;
    [FromServices]
    public ILogger<CatalogServices> Logger { get; } = logger;
};

Exceptions (if any)

See above

.NET Version

10.0.100-preview.6.25358.103

Implementation plan

@copilot To fix this issue:

Metadata

Metadata

Assignees

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

Relationships

None yet

Development

No branches or pull requests

Issue actions