From 7886a25c49c68ad17bc83ad70626ba6ceaed8813 Mon Sep 17 00:00:00 2001 From: Artak Mkrtchyan Date: Thu, 30 Jan 2025 15:07:42 -0800 Subject: [PATCH] Exclude the CreateActionModel method from trimming --- .../src/ApplicationModels/DefaultApplicationModelProvider.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Mvc/Mvc.Core/src/ApplicationModels/DefaultApplicationModelProvider.cs b/src/Mvc/Mvc.Core/src/ApplicationModels/DefaultApplicationModelProvider.cs index 49a162ca31ec0..ff4efb10fb437 100644 --- a/src/Mvc/Mvc.Core/src/ApplicationModels/DefaultApplicationModelProvider.cs +++ b/src/Mvc/Mvc.Core/src/ApplicationModels/DefaultApplicationModelProvider.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Reflection; using Microsoft.AspNetCore.Http; @@ -355,6 +356,8 @@ internal PropertyModel CreatePropertyModel(PropertyInfo propertyInfo) return actionModel; } + [UnconditionalSuppressMessage("AssemblyLoadTrimming", "IL2026:RequiresUnreferencedCode", + Justification = "The method utilizes reflection to get information about the return type of an action")] internal static void AddReturnTypeMetadata(IList selectors, MethodInfo methodInfo) { // Get metadata from return type @@ -372,7 +375,7 @@ internal static void AddReturnTypeMetadata(IList selectors, Metho invokeArgs[0] = methodInfo; invokeArgs[1] = builder; EndpointMetadataPopulator.PopulateMetadataForEndpointMethod.MakeGenericMethod(returnType).Invoke(null, invokeArgs); - + // The metadata is added to the builder's metadata collection. // We need to populate the selectors with that metadata. foreach (var metadata in builder.Metadata)