Skip to content
This repository has been archived by the owner on Jan 1, 2024. It is now read-only.

Improve workaround #8

Merged
merged 4 commits into from
Nov 15, 2023
Merged

Improve workaround #8

merged 4 commits into from
Nov 15, 2023

Conversation

martincostello
Copy link
Owner

@martincostello martincostello commented Nov 14, 2023

Improve warning workarounds for native AoT.

Remove warning workarounds for native AoT.
@martincostello martincostello added the enhancement New feature or request label Nov 14, 2023
@martincostello
Copy link
Owner Author

Need to check if this is a .NET or this-repo issue:

ILC : Trim analysis warning IL2026: __OptionValidationStaticInstances.<Validators_g>F8B1F3D42962A35D8FF1B1489612AEF6C36F3713335EFF79DB68A25973333C495____Attributes..cctor(): Using member 'System.ComponentModel.DataAnnotations.RangeAttribute.RangeAttribute(Type,String,String)' 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. [/home/runner/work/dotnet-8-samples/dotnet-8-samples/src/WeatherApi/WeatherApi.csproj]
ILC : Trim analysis warning IL2026: __OptionValidationStaticInstances.<Validators_g>F8B1F3D42962A35D8FF1B1489612AEF6C36F3713335EFF79DB68A25973333C495____Attributes..cctor(): Using member 'System.ComponentModel.DataAnnotations.RangeAttribute.RangeAttribute(Type,String,String)' 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. [/home/runner/work/dotnet-8-samples/dotnet-8-samples/src/WeatherApi/WeatherApi.csproj]
ILC : Trim analysis warning IL2026: __OptionValidationStaticInstances.<Validators_g>F8B1F3D42962A35D8FF1B1489612AEF6C36F3713335EFF79DB68A25973333C495____Attributes..cctor(): Using member 'System.ComponentModel.DataAnnotations.RangeAttribute.RangeAttribute(Type,String,String)' 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. [/home/runner/work/dotnet-8-samples/dotnet-8-samples/src/WeatherApi/WeatherApi.csproj]

@martincostello
Copy link
Owner Author

Warnings appear to be dotnet/extensions#4622.

@martincostello martincostello marked this pull request as draft November 15, 2023 11:19
@eerhardt
Copy link

Need to check if this is a .NET or this-repo issue:

ILC : Trim analysis warning IL2026: __OptionValidationStaticInstances.<Validators_g>F8B1F3D42962A35D8FF1B1489612AEF6C36F3713335EFF79DB68A25973333C495____Attributes..cctor(): Using member 'System.ComponentModel.DataAnnotations.RangeAttribute.RangeAttribute(Type,String,String)' 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. [/home/runner/work/dotnet-8-samples/dotnet-8-samples/src/WeatherApi/WeatherApi.csproj]
ILC : Trim analysis warning IL2026: __OptionValidationStaticInstances.<Validators_g>F8B1F3D42962A35D8FF1B1489612AEF6C36F3713335EFF79DB68A25973333C495____Attributes..cctor(): Using member 'System.ComponentModel.DataAnnotations.RangeAttribute.RangeAttribute(Type,String,String)' 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. [/home/runner/work/dotnet-8-samples/dotnet-8-samples/src/WeatherApi/WeatherApi.csproj]
ILC : Trim analysis warning IL2026: __OptionValidationStaticInstances.<Validators_g>F8B1F3D42962A35D8FF1B1489612AEF6C36F3713335EFF79DB68A25973333C495____Attributes..cctor(): Using member 'System.ComponentModel.DataAnnotations.RangeAttribute.RangeAttribute(Type,String,String)' 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. [/home/runner/work/dotnet-8-samples/dotnet-8-samples/src/WeatherApi/WeatherApi.csproj]

@martincostello - that issue will resolve those warnings, but it will take a couple servicing releases. The root underlying issue is dotnet/runtime#94119, which will hopefully be fixed in the 8.0.2 servicing release of dotnet/runtime.

@@ -11,8 +11,6 @@
<!-- Add support for Ahead-of-Time (AoT) compilation -->
<PropertyGroup Condition="!$([System.OperatingSystem]::IsMacOS())">

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

macOS is supported in NativeAOT in .NET 8. So this condition can be removed if you want.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it works here, but it doesn't work in Polly 🤔 (logs)

Error: /Users/runner/.dotnet/sdk/8.0.100/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.FrameworkRefe enceResolution.targets(90,5): error NETSDK1204: Ahead-of-time compilation is not supported on the current platform 'osx-x64'. [/Users/runner/work/Polly/Polly/test/Polly.AotTest/Polly.AotTest.csproj]

Looks like it's during dotnet clean (which this repo doesn't do) so maybe that's a bug somewhere?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -11,8 +11,6 @@
<!-- Add support for Ahead-of-Time (AoT) compilation -->
<PropertyGroup Condition="!$([System.OperatingSystem]::IsMacOS())">
<InvariantGlobalization>true</InvariantGlobalization>
<!-- HACK Suppress IL warnings from Microsoft.Extensions.Http.Resilience until 8.0.0 -->

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to disable warnings coming from a specific set of libraries, a strategy I found that works is to use <TrimmerSingleWarn>false</TrimmerSingleWarn> and disable the warning for IL2104 (the warning number for a single warning for a whole library).

And then turn on "single warnings" for the specific libraries you want to suppress. You can see an example of that here:
https://github.com/dotnet/eShop/blob/1e803b09ba8caa3702f037deac837fab956abe33/Directory.Build.targets#L7-L23

Apply suggested pattern to move the ILLink suppressions into their own file out of the project file.
Enable AoT for macOS.
Only update Polly.Core to 8.2.0 to resolve the AoT issue.
@martincostello martincostello changed the title Remove workaround Improve workaround Nov 15, 2023
@martincostello martincostello marked this pull request as ready for review November 15, 2023 17:43
@martincostello martincostello merged commit dbbadc0 into main Nov 15, 2023
3 checks passed
@martincostello martincostello deleted the remove-workaround branch November 15, 2023 17:43
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants