Skip to content
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

Trim warnings when targeting .NET 9 #1549

Open
martincostello opened this issue Oct 10, 2024 · 0 comments
Open

Trim warnings when targeting .NET 9 #1549

martincostello opened this issue Oct 10, 2024 · 0 comments

Comments

@martincostello
Copy link
Contributor

martincostello commented Oct 10, 2024

Using the packages from the latest CI build in an application using Humanizer that I'm trying to get published using native AoT, there's a single remaining warning when targeting net9.0:

/_/src/Humanizer/EnumCache.cs(77): Trim analysis error IL2072: Humanizer.EnumCache`1.TryGetDescription(MemberInfo,String&): 'type' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicProperties', 'DynamicallyAccessedMemberTypes.NonPublicProperties' in call to 'System.Reflection.RuntimeReflectionExtensions.GetRuntimeProperties(Type)'. The return value of method 'System.Object.GetType()' 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.

This appears to correlate to this line of code:

foreach (var property in attrType.GetRuntimeProperties())

I'm not sure what the intended fix for this scenario would be.

I took a look at the code locally, updating the .NET 9 RC2 SDK and adding a net9.0 target and the warning, plus an additional one appear, so these must be due to new annotations in the .NET 9 release.

1>C:\Coding\Humanizr\Humanizer\src\Humanizer\EnumDehumanizeExtensions.cs(30,53,31,72): error IL2026: Using member 'Humanizer.EnumDehumanizeExtensions.DehumanizeTo(String, Type, OnNoMatch)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. The native code for the target enumeration might not be available at runtime.
1>C:\Coding\Humanizr\Humanizer\src\Humanizer\EnumCache.cs(77,38,77,69): error IL2072: 'type' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicProperties', 'DynamicallyAccessedMemberTypes.NonPublicProperties' in call to 'System.Reflection.RuntimeReflectionExtensions.GetRuntimeProperties(Type)'. The return value of method 'System.Object.GetType()' 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant