Skip to content

Validation support in Minimal APIs should be AOT compatible #61339

@mikekistler

Description

@mikekistler

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

AoT-enabled applications will get build warnings if the new validation support in .NET 10 Preview 3 is enabled.

  AotValidation succeeded with 2 warning(s) (0.8s) → bin/Debug/net10.0/AotValidation.dll
    /workspaces/AotValidation/Program.cs(48,16): warning IL2026: Using member 'System.ComponentModel.DataAnnotations.MaxLengthAttribute.MaxLengthAttribute(Int32)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Uses reflection to get the 'Count' property on types that don't implement ICollection. This 'Count' property may be trimmed. Ensure it is preserved.
    /workspaces/AotValidation/obj/Debug/net10.0/Microsoft.AspNetCore.Http.ValidationsGenerator/Microsoft.AspNetCore.Http.ValidationsGenerator.ValidationsGenerator/ValidatableInfoResolver.g.cs(107,32): warning IL2075: 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicProperties' in call to 'System.Type.GetProperty(String)'. The return value of method 'Microsoft.AspNetCore.Http.Validation.Generated.ValidationAttributeCache.CacheKey.ContainingType.get' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.

Expected Behavior

Validation support in Minimal APIs should be AOT compatible.

Steps To Reproduce

Minimal repro in this project:

https://github.com/mikekistler/AotValidation

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

    NativeAOTarea-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etc

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions