Skip to content

Commit caf6b2a

Browse files
lewingCopilot
andauthored
[browser][trimmed] Fix DI generic constraint tests conflicting with trimmability validation (dotnet#134760)
**Cause:** When `PublishTrimmed` is set, `src/tools/illink/src/ILLink.Tasks/build/Microsoft.NET.ILLink.targets` defaults `VerifyDependencyInjectionOpenGenericServiceTrimmability` to `true`, which enables the `Microsoft.Extensions.DependencyInjection.VerifyOpenGenericServiceTrimmability` feature switch. `CallSiteFactory.ValidateTrimmingAnnotations` then rejects the open-generic registrations that these `CallSiteFactoryTest` cases deliberately use (implementation constraints the service type lacks), so container construction throws `ArgumentException`. This is intended validation, not missing metadata. **Fix:** The DI test project opts out of the default, and the five `ActiveIssue` attributes are removed. The only test that needs the switch on, `VerifyOpenGenericTrimmabilityChecks`, sets it explicitly through RemoteExecutor `RuntimeConfigurationOptions`, so its coverage is unchanged. It's also skipped wherever RemoteExecutor is unsupported, including browser. **Validation:** browser-wasm CoreCLR Release, `Microsoft.Extensions.DependencyInjection.Tests` with `EnableAggressiveTrimming=true TestTrimming=true` on Chrome: 884 tests, 847 passed, 37 skipped, 0 failed. All 7 re-enabled cases (4 facts + 3 theory rows) passed, and the published `runtimeconfig.json` shows the switch as `false`. The issue reports the same failure on Mono browser trimming; only CoreCLR was run locally. Resolves dotnet#134266 > [!NOTE] > This PR was generated with GitHub Copilot assistance. Co-authored-by: Copilot App <[email protected]>
1 parent 3c7c356 commit caf6b2a

2 files changed

Lines changed: 3 additions & 5 deletions

File tree

‎src/libraries/Microsoft.Extensions.DependencyInjection/tests/DI.Tests/Microsoft.Extensions.DependencyInjection.Tests.csproj‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
<!-- https://github.com/dotnet/runtime/issues/126862 -->
1313
<EnableTrimAnalyzer>false</EnableTrimAnalyzer>
1414
<EnableAotAnalyzer>false</EnableAotAnalyzer>
15+
<!-- ILLink enables open-generic trimmability validation by default, but CallSiteFactoryTest deliberately registers
16+
constraint shapes it rejects. VerifyOpenGenericTrimmabilityChecks enables the validation explicitly. -->
17+
<VerifyDependencyInjectionOpenGenericServiceTrimmability>false</VerifyDependencyInjectionOpenGenericServiceTrimmability>
1518
</PropertyGroup>
1619

1720
<ItemGroup>

‎src/libraries/Microsoft.Extensions.DependencyInjection/tests/DI.Tests/ServiceLookup/CallSiteFactoryTest.cs‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,6 @@ public void CreateCallSite_UsesLongestResolvableConstructorWhenDeclaredAfterShor
271271
}
272272

273273
[Fact]
274-
[ActiveIssue("https://github.com/dotnet/runtime/issues/134266", typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltWithAggressiveTrimming), nameof(PlatformDetection.IsBrowser))]
275274
public void CreateCallSite_Throws_IfClosedTypeDoesNotSatisfyStructGenericConstraint()
276275
{
277276
// Arrange
@@ -286,7 +285,6 @@ public void CreateCallSite_Throws_IfClosedTypeDoesNotSatisfyStructGenericConstra
286285
}
287286

288287
[Fact]
289-
[ActiveIssue("https://github.com/dotnet/runtime/issues/134266", typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltWithAggressiveTrimming), nameof(PlatformDetection.IsBrowser))]
290288
public void CreateCallSite_ReturnsService_IfClosedTypeSatisfiesStructGenericConstraint()
291289
{
292290
// Arrange
@@ -331,7 +329,6 @@ public void CreateCallSite_ReturnsService_IfClosedTypeSatisfiesClassGenericConst
331329
}
332330

333331
[Fact]
334-
[ActiveIssue("https://github.com/dotnet/runtime/issues/134266", typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltWithAggressiveTrimming), nameof(PlatformDetection.IsBrowser))]
335332
public void CreateCallSite_Throws_IfClosedTypeDoesNotSatisfyNewGenericConstraint()
336333
{
337334
// Arrange
@@ -346,7 +343,6 @@ public void CreateCallSite_Throws_IfClosedTypeDoesNotSatisfyNewGenericConstraint
346343
}
347344

348345
[Fact]
349-
[ActiveIssue("https://github.com/dotnet/runtime/issues/134266", typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltWithAggressiveTrimming), nameof(PlatformDetection.IsBrowser))]
350346
public void CreateCallSite_ReturnsService_IfClosedTypeSatisfiesNewGenericConstraint()
351347
{
352348
// Arrange
@@ -532,7 +528,6 @@ public void CreateCallSite_ReturnsMatchingTypes_IfClosedTypeSatisfiesBaseClassCo
532528
[InlineData(typeof(IFakeOpenGenericService<int>), default(int), new[] { typeof(FakeOpenGenericService<int>), typeof(ClassWithStructConstraint<int>), typeof(ClassWithNewConstraint<int>), typeof(ClassWithSelfReferencingConstraint<int>) })]
533529
[InlineData(typeof(IFakeOpenGenericService<string>), "", new[] { typeof(FakeOpenGenericService<string>), typeof(ClassWithClassConstraint<string>), typeof(ClassWithInterfaceConstraint<string>), typeof(ClassWithSelfReferencingConstraint<string>) })]
534530
[InlineData(typeof(IFakeOpenGenericService<int[]>), new[] { 1, 2, 3 }, new[] { typeof(FakeOpenGenericService<int[]>), typeof(ClassWithClassConstraint<int[]>), typeof(ClassWithInterfaceConstraint<int[]>) })]
535-
[ActiveIssue("https://github.com/dotnet/runtime/issues/134266", typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltWithAggressiveTrimming), nameof(PlatformDetection.IsBrowser))]
536531
public void CreateCallSite_ReturnsMatchingTypesThatMatchCorrectConstraints(Type closedServiceType, object value, Type[] matchingImplementationTypes)
537532
{
538533
// Arrange

0 commit comments

Comments
 (0)