Skip to content

ValidateNever attribute seems to be ignored #64785

@illunix

Description

@illunix

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

As you can see in my code I added ValidateNever attribute everywhere I Manufacturer appears

[ValidateNever]
public sealed record GetItemsQuery([property: ValidateNever] Manufacturer? Manufacturer) : IQuery<ItemDto>
{
    public static ValueTask<GetItemsQuery?> BindAsync(
        HttpContext ctx,
        ParameterInfo param
    )
    {
        const string manufacturerKey = "manufacturer";

        Manufacturer? manufacturer = null;
        var manufacturerParam = ctx.Request.Query[manufacturerKey];
        if (!string.IsNullOrEmpty(manufacturerParam))
            manufacturer = Manufacturer.TryFromName(
                manufacturerParam,
                ignoreCase: true,
                out var m
            )
                ? m
                : null;

        return ValueTask.FromResult<GetItemsQuery?>(new(manufacturer));
    }
}
[ValidateNever]
public sealed class Manufacturer : SmartEnum<Manufacturer>
{
    public static readonly Manufacturer Test1 = new("Test 1", 1);
    public static readonly Manufacturer Test2 = new("Test 2", 2);
    public static readonly Manufacturer Test3 = new("Test 3", 3);
    // etc.
}

Expected Behavior

Should skip validating Manufacturer property or whole GetItemsQuery object

Steps To Reproduce

So the package I use for SmartEnum is Ardalis.SmartEnum
Also my Manufacturer class exceedes 32 properties with Manufacturer type

Exceptions (if any)

Maximum validation depth of 32 exceeded at 'Manufacturer.List[0].List[0].List[0].List[0].List[0].List[0].List[0].List[0].List[0].List[0].List[0].List[0].List[0].List[0].List[0].List[0].List[0].List[0].List[0].List[0].List[0].List[0].List[0].List[0].List[0].List[0].List[0].List[0].List[0].List[0].List[0]' in 'Manufacturer'. This is likely caused by a circular reference in the object graph. Consider increasing the MaxDepth in ValidationOptions if deeper validation is required.
System.InvalidOperationException: Maximum validation depth of 32 exceeded at 'Manufacturer.List[0].List[0].List[0].List[0].List[0].List[0].List[0].List[0].List[0].List[0].List[0].List[0].List[0].List[0].List[0].List[0].List[0].List[0].List[0].List[0].List[0].List[0].List[0].List[0].List[0].List[0].List[0].List[0].List[0].List[0].List[0]' in 'Manufacturer'. This is likely caused by a circular reference in the object graph. Consider increasing the MaxDepth in ValidationOptions if deeper validation is required.

.NET Version

10.0.101

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