Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
Playing about with the native AoT support for the OpenAPI functionality with nightly builds of .NET 9 preview.5, trim warnings are generated from assemblies referenced by Microsoft.AspNetCore.OpenApi. This causes an application using TreatWarningsAsErrors=true
to fail to compile when published.
Below are the warnings that appear to come from the framework itself when using MapOpenApi()
:
ILC : Trim analysis error IL2026: Microsoft.AspNetCore.Mvc.ApiExplorer.EndpointMetadataApiDescriptionProvider.CreateApiDescription(RouteEndpoint,String,MethodInfo,Boolean): Using member 'Microsoft.AspNetCore.Http.PropertyAsParameterInfo.Flatten(ParameterInfo[],ParameterBindingMethodCache)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Uses unbounded Reflection to access parameter type constructors.
ILC : AOT analysis error IL3050: Microsoft.AspNetCore.Mvc.ApiExplorer.EndpointMetadataApiDescriptionProvider.AddSupportedResponseTypes(IList`1<ApiResponseType>,Type,EndpointMetadataCollection): Using member 'Microsoft.Extensions.Internal.CoercedAwaitableInfo.IsTypeAwaitable(Type,CoercedAwaitableInfo&)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. Dynamically generates calls to FSharpAsync.
ILC : Trim analysis error IL2067: Microsoft.AspNetCore.Mvc.ApiExplorer.EndpointMetadataApiDescriptionProvider.AddSupportedResponseTypes(IList`1<ApiResponseType>,Type,EndpointMetadataCollection): 'type' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods', 'DynamicallyAccessedMemberTypes.NonPublicMethods', 'DynamicallyAccessedMemberTypes.PublicProperties', 'DynamicallyAccessedMemberTypes.NonPublicProperties' in call to 'Microsoft.Extensions.Internal.CoercedAwaitableInfo.IsTypeAwaitable(Type,CoercedAwaitableInfo&)'. The parameter 'returnType' of method 'Microsoft.AspNetCore.Mvc.ApiExplorer.EndpointMetadataApiDescriptionProvider.AddSupportedResponseTypes(IList`1<ApiResponseType>,Type,EndpointMetadataCollection)' 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.
ILC : Trim analysis error IL2026: Microsoft.AspNetCore.Mvc.ApiExplorer.EndpointMetadataApiDescriptionProvider.GetBindingSourceAndName(ParameterInfo,RoutePattern,Boolean): Using member 'Microsoft.AspNetCore.Http.ParameterBindingMethodCache.HasBindAsyncMethod(ParameterInfo)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Performs reflection on type hierarchy. This cannot be statically analyzed.
ILC : AOT analysis error IL3050: Microsoft.AspNetCore.Mvc.ApiExplorer.EndpointMetadataApiDescriptionProvider.GetBindingSourceAndName(ParameterInfo,RoutePattern,Boolean): Using member 'Microsoft.AspNetCore.Http.ParameterBindingMethodCache.HasBindAsyncMethod(ParameterInfo)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. Performs reflection on type hierarchy. This cannot be statically analyzed.
ILC : Trim analysis error IL2026: Microsoft.AspNetCore.Mvc.ApiExplorer.EndpointMetadataApiDescriptionProvider.GetBindingSourceAndName(ParameterInfo,RoutePattern,Boolean): Using member 'Microsoft.AspNetCore.Http.ParameterBindingMethodCache.HasTryParseMethod(Type)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Performs reflection on type hierarchy. This cannot be statically analyzed.
ILC : AOT analysis error IL3050: Microsoft.AspNetCore.Mvc.ApiExplorer.EndpointMetadataApiDescriptionProvider.GetBindingSourceAndName(ParameterInfo,RoutePattern,Boolean): Using member 'Microsoft.AspNetCore.Http.ParameterBindingMethodCache.HasTryParseMethod(Type)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. Performs reflection on type hierarchy. This cannot be statically analyzed.
ILC : Trim analysis error IL2026: Microsoft.AspNetCore.Mvc.ApiExplorer.EndpointMetadataApiDescriptionProvider.GetBindingSourceAndName(ParameterInfo,RoutePattern,Boolean): Using member 'Microsoft.AspNetCore.Http.ParameterBindingMethodCache.HasTryParseMethod(Type)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Performs reflection on type hierarchy. This cannot be statically analyzed.
ILC : AOT analysis error IL3050: Microsoft.AspNetCore.Mvc.ApiExplorer.EndpointMetadataApiDescriptionProvider.GetBindingSourceAndName(ParameterInfo,RoutePattern,Boolean): Using member 'Microsoft.AspNetCore.Http.ParameterBindingMethodCache.HasTryParseMethod(Type)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. Performs reflection on type hierarchy. This cannot be statically analyzed.
ILC : Trim analysis error IL2026: Microsoft.AspNetCore.Mvc.ModelBinding.ModelMetadata.InitializeTypeInformation(): Using member 'System.ComponentModel.TypeDescriptor.GetConverter(Type)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Generic TypeConverters may require the generic types to be annotated. For example, NullableConverter requires the underlying type to be DynamicallyAccessedMembers All.
ILC : Trim analysis error IL2072: Microsoft.AspNetCore.Mvc.ModelBinding.ModelMetadata.InitializeTypeInformation(): 'type' argument does not satisfy 'DynamicallyAccessedMemberTypes.All' in call to 'System.ComponentModel.TypeDescriptor.GetConverter(Type)'. The return value of method 'Microsoft.AspNetCore.Mvc.ModelBinding.ModelMetadata.ModelType.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.
ILC : Trim analysis error IL2072: Microsoft.AspNetCore.Mvc.ModelBinding.ModelMetadata.InitializeTypeInformation(): 'queryType' argument does not satisfy 'DynamicallyAccessedMemberTypes.Interfaces' in call to 'Microsoft.Extensions.Internal.ClosedGenericMatcher.ExtractGenericInterface(Type,Type)'. The return value of method 'Microsoft.AspNetCore.Mvc.ModelBinding.ModelMetadata.ModelType.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.
ILC : Trim analysis error IL2072: Microsoft.AspNetCore.Mvc.ModelBinding.ModelMetadata.InitializeTypeInformation(): 'queryType' argument does not satisfy 'DynamicallyAccessedMemberTypes.Interfaces' in call to 'Microsoft.Extensions.Internal.ClosedGenericMatcher.ExtractGenericInterface(Type,Type)'. The return value of method 'Microsoft.AspNetCore.Mvc.ModelBinding.ModelMetadata.ModelType.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.
ILC : Trim analysis error IL2026: Microsoft.AspNetCore.Mvc.ModelBinding.ModelMetadata.FindTryParseMethod(Type): Using member 'Microsoft.AspNetCore.Http.ParameterBindingMethodCache.FindTryParseMethod(Type)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Performs reflection on type hierarchy. This cannot be statically analyzed.
ILC : AOT analysis error IL3050: Microsoft.AspNetCore.Mvc.ModelBinding.ModelMetadata.FindTryParseMethod(Type): Using member 'Microsoft.AspNetCore.Http.ParameterBindingMethodCache.FindTryParseMethod(Type)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. Performs reflection on type hierarchy. This cannot be statically analyzed.
ILC : Trim analysis error IL2026: Microsoft.AspNetCore.Mvc.ModelBinding.ModelMetadata..cctor(): Using member 'Microsoft.AspNetCore.Http.ParameterBindingMethodCache.ParameterBindingMethodCache(Boolean)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Uses unbounded Reflection to inspect property types.
The repro below includes some others from my own code, but ignore those as I was just messing around trying to replicate some NSwag functionality I have to generate examples using the new functionality for OpenAPI (from where the suggestion in #56022 came from).
Expected Behavior
The application builds with no trim warnings from ASP.NET Core itself when MapOpenApi()
is used in an application published for native AoT.
Steps To Reproduce
- Clone martincostello/api@b490334
- Run
build.ps1 -SkipTests
from the root of the repository
Exceptions (if any)
None.
.NET Version
9.0.100-preview.5.24281.15
Anything else?
No response