-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MissingMethodException thrown in native AoT application using AddStandardResilienceHandler() with .NET 9 preview.2 #105034
Comments
Whether it's a problem or not I don't know, but I tried to restore the functionality by adding the following to my project file and I get these errors: <PropertyGroup>
<TrimmerSingleWarn>false</TrimmerSingleWarn>
</PropertyGroup>
<ItemGroup>
<TrimmerRootAssembly Include="Microsoft.Extensions.Http.Resilience" />
</ItemGroup> LondonTravel.Skill failed with errors (40.5s) → artifacts\bin\LondonTravel.Skill\release\LondonTravel.Skill.dll
ILC : Trim analysis error IL2026: Microsoft.Extensions.Http.Resilience.WeightedGroupsRoutingOptions.Groups: Using member 'System.ComponentModel.DataAnnotations.LengthAttribute.LengthAttribute(Int32,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. [C:\Coding\martincostello\alexa-london-travel\src\LondonTravel.Skill\LondonTravel.Skill.csproj]
ILC : Trim analysis error IL2026: Microsoft.Extensions.Http.Resilience.WeightedGroupsRoutingOptions.Groups: Using member 'System.ComponentModel.DataAnnotations.LengthAttribute.LengthAttribute(Int32,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. [C:\Coding\martincostello\alexa-london-travel\src\LondonTravel.Skill\LondonTravel.Skill.csproj]
ILC : Trim analysis error IL2026: Microsoft.Extensions.Http.Resilience.UriEndpointGroup.Endpoints: Using member 'System.ComponentModel.DataAnnotations.LengthAttribute.LengthAttribute(Int32,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. [C:\Coding\martincostello\alexa-london-travel\src\LondonTravel.Skill\LondonTravel.Skill.csproj]
ILC : Trim analysis error IL2026: Microsoft.Extensions.Http.Resilience.UriEndpointGroup.Endpoints: Using member 'System.ComponentModel.DataAnnotations.LengthAttribute.LengthAttribute(Int32,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. [C:\Coding\martincostello\alexa-london-travel\src\LondonTravel.Skill\LondonTravel.Skill.csproj]
ILC : Trim analysis error IL2026: Microsoft.Extensions.Http.Resilience.OrderedGroupsRoutingOptions.Groups: Using member 'System.ComponentModel.DataAnnotations.LengthAttribute.LengthAttribute(Int32,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. [C:\Coding\martincostello\alexa-london-travel\src\LondonTravel.Skill\LondonTravel.Skill.csproj]
ILC : Trim analysis error IL2026: Microsoft.Extensions.Http.Resilience.OrderedGroupsRoutingOptions.Groups: Using member 'System.ComponentModel.DataAnnotations.LengthAttribute.LengthAttribute(Int32,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. [C:\Coding\martincostello\alexa-london-travel\src\LondonTravel.Skill\LondonTravel.Skill.csproj] Looking at the code, the warnings are being suppressed using pragmas rather than attributes, so the trimmer can't reason about the intentional suppressions. |
I've also tried the following, but that doesn't seem to be working either: <ItemGroup>
<TrimmerRootDescriptor Include="TrimmerRoots.xml" />
</ItemGroup> <linker>
<assembly fullname="Microsoft.Extensions.Http.Resilience">
<type fullname="Microsoft.Extensions.Http.Resilience.Internal.HttpKey" preserve="all" />
</assembly>
<assembly fullname="Polly.Core">
<type fullname="Polly.Registry.ResiliencePipelineRegistryOptions`1" preserve="all" />
</assembly>
</linker> |
Still observing this issue with .NET 9 preview 3. |
I've been able to reproduce this outside of my deployed AWS Lambda function using the new AoT support in MSTest here: martincostello/alexa-london-travel#1157 |
Minimal repro added here: https://github.com/martincostello/dotnet-extensions-5062-repro |
@iliar-turdushev could you please have a look? |
Re-tested with preview 4, still an issue. |
Still repros with .NET 9 preview 5. |
Still an issue with .NET 9 preview 6. |
@eerhardt @MichalStrehovsky Sorry to ping directly, but you're the two of the native AoT experts I know of. It concerns me that this still isn't working, telling the trimmer to preserve the type doesn't seem to work #105034, and this issue has been open for nearly 4 months now and the .NET 9 release is starting to wrap up the previews. Feels like either the fix should be trivial if it's here, or there's an issue in the trimmer itself. Either way I don't know enough in this area to resolve it myself, otherwise I'd have dug into it myself and offered a PR by now. |
Tagging subscribers to this area: @dotnet/area-extensions-dependencyinjection |
Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas |
This looks like a native AOT bug. Moved this to dotnet/runtime. |
Description
I've been testing an application of mine which is a native AoT application deployed to AWS Lambda with .NET 9. As part of the testing I wanted to try out the new JsonSerializerOptions.AllowOutOfOrderMetadataProperties property to support using polymorphism with the JSON serialization for types used by the AWS Alexa skills API.
Having resolved an issue with getting that to work properly, I've run into a new issue where trying to resolve an
HttpClient
with HttpClientFactory whenAddStandardResilienceHandler()
has been associated with all instances causes aMissingMethodException
to be thrown (martincostello/alexa-london-travel#1116 (comment)).It could be that this is a trimmer issue (or something wrong in my code that wasn't wrong before), but as the
Microsoft.Extensions.Http.Resilience.Internal.HttpKey
type is defined in this repo and removing the call toAddStandardResilienceHandler()
(see martincostello/alexa-london-travel@e3e7de1) fixes the issue, I figured this was the best first port of call.Reproduction Steps
I'll try and create a branch with an easy-to-execute local repro later, but the code with the issue is at this commit: martincostello/alexa-london-travel@50eb0a2.1. Clone martincostello/alexa-london-travel@75e5c8b2. Runbuild.ps1
in the root directory of the repository.Expected behavior
HttpClient
requests using resilience are correctly resolved from DI and work as expected.Actual behavior
A
MissingMethodException
is thrown from here:https://github.com/dotnet/extensions/blob/16b40667278d24a23af0c839f4c277499b3fee19/src/Libraries/Microsoft.Extensions.Http.Resilience/Resilience/ResilienceHttpClientBuilderExtensions.Resilience.cs#L80
Regression?
From .NET 8, yes.
Known Workarounds
None.
Configuration
9.0.100-preview.2.24157.14
9.0.0-preview.2.24157.4
Other information
No response
The text was updated successfully, but these errors were encountered: