Humanizer
Humanizer copied to clipboard
Trim warnings when targeting .NET 9
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:
https://github.com/Humanizr/Humanizer/blob/38b2d1f78bbb8e2346f53033d4f5ee95b26d8035/src/Humanizer/EnumCache.cs#L77
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.