-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Unactionable Trim warnings when referencing both Npgsql and Microsoft.Extensions.Http.Resilience #97057
Comments
Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas Issue DetailsDescriptionWhen referencing 2 totally different packages independently, I'm able to publish an app without any warnings. But when I combine them and use them together, I'm getting trim warnings that I can't fix as a end-user developer. Reproduction Steps
csproj: <Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<InvariantGlobalization>true</InvariantGlobalization>
<PublishAot>true</PublishAot>
<TrimmerSingleWarn>false</TrimmerSingleWarn>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Npgsql.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Http.Resilience" Version="8.2.0-preview.24066.3" />
</ItemGroup>
</Project> (Note that Program.cs: var builder = WebApplication.CreateSlimBuilder(args);
builder.Services.AddNpgsqlDataSource(builder.Configuration.GetConnectionString("npgsql") ?? throw new Exception("configure npgsql"));
builder.Services.ConfigureHttpClientDefaults(http =>
{
http.AddStandardResilienceHandler();
});
var app = builder.Build();
app.MapGet("/", () => "hello, world");
app.Run(); Expected behaviorNo publish warnings. Actual behavior
Note that if you comment out either line 2 or 3 in the Regression?No response Known WorkaroundsNo response ConfigurationNo response Other informationThe reason this shows up is because I see the same warnings are being suppressed on the base DbConnectionStringBuilder: runtime/src/libraries/System.Data.Common/src/System/Data/Common/DbConnectionStringBuilder.cs Lines 15 to 20 in 613a13f
See also:
Should NpgsqlConnectionStringBuilder be suppressing these warnings as well?
|
Looks like the IL2113 warnings only show up for PublishAot. The IL2112 shows up for both PublishAot and PublishTrimmed. This is also potentially related to #88512 that was filed due to the same |
@LakshanF as this is related to This will teach us to think more than twice before putting any annotation on a virtual/interface method :-) |
Since these warnings are being suppressed on the base DbConnectionStringBuilder, is it safe to assume that we can suppress them on NpgsqlConnectionStringBuilder as well? NpgsqlConnectionStringBuilder isn't doing anything special here - it is just trying to implement the ICustomTypeDescriptor overrides (which have RequiresUnreferencedCode on them - so any real callers of those methods will get warnings).
The root of need for Lines 44 to 45 in 5598dac
Lines 98 to 107 in 5598dac
In order to get all the attributes for a Type, we need to walk all the interfaces the Type implements and get events, properties, etc. on it. I tried lessening the Lines 323 to 327 in 5598dac
Lines 425 to 430 in 5598dac
AFAIK, the trim analysis has special handling of Also note that I ended up needing to preserve:
Which would probably cause us to have this same problem anyway - it would still need to preserve the ICustomTypeDescriptor interface and all its methods. |
#88512 is about introducing annotations that would allow walking base hierarchies and looking for members without having to preserve things to the extent that .All does. (we could preserve e.g. all methods, including those on base types, without having to go all in with .All) The problem that .All is causing here is that it will walk into the list of implemented interfaces and apply .All to all of the methods on those interfaces as well (that's what the warnings are about). If we could say The fact we need to mark PublicMethods is annoying and the linked code is atrocious, but maybe it would still be okay because it's just the public methods and there don't appear to be any public methods on Being more targeted causes fewer ripple effects. Not saying we don't have a bug with the suppression not working right, but we wouldn't run into it if we didn't use |
- Split ThrowIfUnsupported out into a nested class of JsonDynamicTypeInfoResolverFactory to avoid erroneous warnings. - Suppress warnings on NpgsqlConnectionStringBuilder to match base DbConnectionStringBuilder suppressions. See dotnet/runtime#97057 for an explanation of why these warnings happen. Fix npgsql#5577
- Split ThrowIfUnsupported out into a nested class of JsonDynamicTypeInfoResolverFactory to avoid erroneous warnings. - Suppress warnings on NpgsqlConnectionStringBuilder to match base DbConnectionStringBuilder suppressions. See dotnet/runtime#97057 for an explanation of why these warnings happen. Fix npgsql#5577
FYI - I opened npgsql/npgsql#5578 to add the same suppressions to |
Description
When referencing 2 totally different packages independently, I'm able to publish an app without any warnings. But when I combine them and use them together, I'm getting trim warnings that I can't fix as a end-user developer.
Reproduction Steps
dotnet publish
the following app:csproj:
(Note that
<PackageReference Include="Microsoft.Extensions.Http.Resilience" Version="8.2.0-preview.24066.3" />
needs a nuget.config entry for<add key="dotnet8" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet8/nuget/v3/index.json" />
)Program.cs:
Expected behavior
No publish warnings.
Actual behavior
Note that if you comment out either line 2 or 3 in the
Program.cs
, there are no warnings. But when you have both, then the warnings show up.Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
The reason this shows up is because
AddStandardResilienceHandler()
brings in a bunch of System.ComponentModel interfaces likeICustomTypeDescriptor
.I see the same warnings are being suppressed on the base DbConnectionStringBuilder:
runtime/src/libraries/System.Data.Common/src/System/Data/Common/DbConnectionStringBuilder.cs
Lines 15 to 20 in 613a13f
See also:
Should NpgsqlConnectionStringBuilder be suppressing these warnings as well?
cc @vitek-karas @sbomer @roji
The text was updated successfully, but these errors were encountered: