diff --git a/eng/testing/tests.singlefile.targets b/eng/testing/tests.singlefile.targets
index 18b342db71ac0..1cfa4ba1cdeca 100644
--- a/eng/testing/tests.singlefile.targets
+++ b/eng/testing/tests.singlefile.targets
@@ -26,7 +26,7 @@
$(CoreCLRILCompilerDir)netstandard/ILCompiler.Build.Tasks.dll$(CoreCLRAotSdkDir)$(NetCoreAppCurrentTestHostSharedFrameworkPath)
- $(NoWarn);IL3050;IL3051;IL3052;IL3055;IL1005;IL3002
+ $(NoWarn);IL3050;IL3051;IL3052;IL3054;IL3055;IL1005;IL3002falsetrue
diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/FlowAnnotations.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/FlowAnnotations.cs
index 8bb4badad9b70..1a4844b8f418b 100644
--- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/FlowAnnotations.cs
+++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/FlowAnnotations.cs
@@ -311,16 +311,18 @@ protected override TypeAnnotations CreateValueFromKey(TypeDesc key)
TypeDesc baseType = key.BaseType;
while (baseType != null)
{
- TypeDefinition baseTypeDef = reader.GetTypeDefinition(((EcmaType)baseType.GetTypeDefinition()).Handle);
- typeAnnotation |= GetMemberTypesForDynamicallyAccessedMembersAttribute(reader, baseTypeDef.GetCustomAttributes());
+ var ecmaBaseType = (EcmaType)baseType.GetTypeDefinition();
+ TypeDefinition baseTypeDef = ecmaBaseType.MetadataReader.GetTypeDefinition(ecmaBaseType.Handle);
+ typeAnnotation |= GetMemberTypesForDynamicallyAccessedMembersAttribute(ecmaBaseType.MetadataReader, baseTypeDef.GetCustomAttributes());
baseType = baseType.BaseType;
}
// And inherit them from interfaces
foreach (DefType runtimeInterface in key.RuntimeInterfaces)
{
- TypeDefinition interfaceTypeDef = reader.GetTypeDefinition(((EcmaType)runtimeInterface.GetTypeDefinition()).Handle);
- typeAnnotation |= GetMemberTypesForDynamicallyAccessedMembersAttribute(reader, interfaceTypeDef.GetCustomAttributes());
+ var ecmaInterface = (EcmaType)runtimeInterface.GetTypeDefinition();
+ TypeDefinition interfaceTypeDef = ecmaInterface.MetadataReader.GetTypeDefinition(ecmaInterface.Handle);
+ typeAnnotation |= GetMemberTypesForDynamicallyAccessedMembersAttribute(ecmaInterface.MetadataReader, interfaceTypeDef.GetCustomAttributes());
}
}
catch (TypeSystemException)
diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/EmbeddedTrimmingDescriptorNode.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/EmbeddedTrimmingDescriptorNode.cs
index b50b35cf7c4bf..60aa822c2759a 100644
--- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/EmbeddedTrimmingDescriptorNode.cs
+++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/EmbeddedTrimmingDescriptorNode.cs
@@ -60,7 +60,7 @@ public override IEnumerable GetStaticDependencies(NodeFacto
protected override string GetName(NodeFactory factory)
{
- return $"Getting embedded descriptor file from {_module.GetDisplayName()}";
+ return $"Getting embedded descriptor file from {_module.ToString()}";
}
public override bool InterestingForDynamicDependencyAnalysis => false;
diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ReflectableFieldNode.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ReflectableFieldNode.cs
index 4f4cd477d44e3..dd5b429d10438 100644
--- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ReflectableFieldNode.cs
+++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ReflectableFieldNode.cs
@@ -83,14 +83,17 @@ public override IEnumerable GetStaticDependencies(NodeFacto
}
}
- // Runtime reflection stack needs to obtain the type handle of the field
- // (but there's no type handles for function pointers)
- TypeDesc fieldTypeToCheck = _field.FieldType;
- while (fieldTypeToCheck.IsParameterizedType)
- fieldTypeToCheck = ((ParameterizedType)fieldTypeToCheck).ParameterType;
-
- if (!fieldTypeToCheck.IsFunctionPointer)
- dependencies.Add(factory.MaximallyConstructableType(_field.FieldType.NormalizeInstantiation()), "Type of the field");
+ if (!_field.OwningType.IsCanonicalSubtype(CanonicalFormKind.Any))
+ {
+ // Runtime reflection stack needs to obtain the type handle of the field
+ // (but there's no type handles for function pointers)
+ TypeDesc fieldTypeToCheck = _field.FieldType;
+ while (fieldTypeToCheck.IsParameterizedType)
+ fieldTypeToCheck = ((ParameterizedType)fieldTypeToCheck).ParameterType;
+
+ if (!fieldTypeToCheck.IsFunctionPointer)
+ dependencies.Add(factory.MaximallyConstructableType(_field.FieldType.NormalizeInstantiation()), "Type of the field");
+ }
return dependencies;
}
diff --git a/src/libraries/Microsoft.Extensions.DependencyModel/tests/DependencyContextLoaderTests.cs b/src/libraries/Microsoft.Extensions.DependencyModel/tests/DependencyContextLoaderTests.cs
index e7e5ce6ecb816..71f7a3f7e23ca 100644
--- a/src/libraries/Microsoft.Extensions.DependencyModel/tests/DependencyContextLoaderTests.cs
+++ b/src/libraries/Microsoft.Extensions.DependencyModel/tests/DependencyContextLoaderTests.cs
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
using FluentAssertions;
+using System;
using System.IO;
using System.Reflection;
using Xunit;
@@ -76,7 +77,8 @@ public void LoadLoadsExtraPaths()
context.RuntimeLibraries.Should().Contain(l => l.Name == "System.Banana");
}
- [Fact]
+ // Load method is marked RequiresAssemblyFiles so this test doesn't make sense on single file
+ [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.HasAssemblyFiles))]
public void LoadCanLoadANonEntryAssembly()
{
var loader = new DependencyContextLoader();
diff --git a/src/libraries/Microsoft.Extensions.FileSystemGlobbing/tests/Microsoft.Extensions.FileSystemGlobbing.Tests.csproj b/src/libraries/Microsoft.Extensions.FileSystemGlobbing/tests/Microsoft.Extensions.FileSystemGlobbing.Tests.csproj
index 18043e2391cb0..f96695c91c015 100644
--- a/src/libraries/Microsoft.Extensions.FileSystemGlobbing/tests/Microsoft.Extensions.FileSystemGlobbing.Tests.csproj
+++ b/src/libraries/Microsoft.Extensions.FileSystemGlobbing/tests/Microsoft.Extensions.FileSystemGlobbing.Tests.csproj
@@ -5,6 +5,10 @@
true
+
+
+
+
diff --git a/src/libraries/Microsoft.Extensions.FileSystemGlobbing/tests/default.rd.xml b/src/libraries/Microsoft.Extensions.FileSystemGlobbing/tests/default.rd.xml
new file mode 100644
index 0000000000000..2c14c77dbb3c3
--- /dev/null
+++ b/src/libraries/Microsoft.Extensions.FileSystemGlobbing/tests/default.rd.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
diff --git a/src/libraries/Microsoft.Extensions.HostFactoryResolver/tests/HostFactoryResolverTests.cs b/src/libraries/Microsoft.Extensions.HostFactoryResolver/tests/HostFactoryResolverTests.cs
index fe26636fa8501..b35db51ec0da2 100644
--- a/src/libraries/Microsoft.Extensions.HostFactoryResolver/tests/HostFactoryResolverTests.cs
+++ b/src/libraries/Microsoft.Extensions.HostFactoryResolver/tests/HostFactoryResolverTests.cs
@@ -108,6 +108,7 @@ public void CreateHostBuilderPattern_CanFindHostBuilder()
[Fact]
[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(CreateHostBuilderPatternTestSite.Program))]
[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(Host))]
+ [ActiveIssue("https://github.com/dotnet/runtime/issues/73420", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))]
public void CreateHostBuilderPattern_CanFindServiceProvider()
{
var factory = HostFactoryResolver.ResolveServiceProviderFactory(typeof(CreateHostBuilderPatternTestSite.Program).Assembly);
@@ -137,6 +138,7 @@ public void CreateHostBuilderPattern__Invalid_CantFindServiceProvider()
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))]
[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(NoSpecialEntryPointPattern.Program))]
+ [ActiveIssue("https://github.com/dotnet/runtime/issues/73420", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))]
public void NoSpecialEntryPointPattern()
{
var factory = HostFactoryResolver.ResolveServiceProviderFactory(typeof(NoSpecialEntryPointPattern.Program).Assembly, s_WaitTimeout);
@@ -235,6 +237,7 @@ public void NoSpecialEntryPointPatternHangs()
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))]
[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(NoSpecialEntryPointPatternMainNoArgs.Program))]
+ [ActiveIssue("https://github.com/dotnet/runtime/issues/73420", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))]
public void NoSpecialEntryPointPatternMainNoArgs()
{
var factory = HostFactoryResolver.ResolveServiceProviderFactory(typeof(NoSpecialEntryPointPatternMainNoArgs.Program).Assembly, s_WaitTimeout);
@@ -244,6 +247,8 @@ public void NoSpecialEntryPointPatternMainNoArgs()
}
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))]
+ [DynamicDependency(DynamicallyAccessedMemberTypes.All, "Program", "TopLevelStatements")]
+ [ActiveIssue("https://github.com/dotnet/runtime/issues/73420", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))]
public void TopLevelStatements()
{
var assembly = Assembly.Load("TopLevelStatements");
@@ -254,6 +259,7 @@ public void TopLevelStatements()
}
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))]
+ [DynamicDependency(DynamicallyAccessedMemberTypes.All, "Program", "TopLevelStatementsTestsTimeout")]
public void TopLevelStatementsTestsTimeout()
{
var assembly = Assembly.Load("TopLevelStatementsTestsTimeout");
@@ -264,6 +270,8 @@ public void TopLevelStatementsTestsTimeout()
}
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))]
+ [ActiveIssue("https://github.com/dotnet/runtime/issues/73420", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))]
+ [DynamicDependency(DynamicallyAccessedMemberTypes.All, "Program", "ApplicationNameSetFromArgument")]
public void ApplicationNameSetFromArgument()
{
Assembly assembly = Assembly.Load("ApplicationNameSetFromArgument");
@@ -276,6 +284,7 @@ public void ApplicationNameSetFromArgument()
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsThreadingSupported))]
[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(NoSpecialEntryPointPattern.Program))]
+ [ActiveIssue("https://github.com/dotnet/runtime/issues/73420", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))]
public void NoSpecialEntryPointPatternCanRunInParallel()
{
var factory = HostFactoryResolver.ResolveServiceProviderFactory(typeof(NoSpecialEntryPointPattern.Program).Assembly, s_WaitTimeout);
diff --git a/src/libraries/Microsoft.Extensions.Hosting/tests/UnitTests/HostBuilderTests.cs b/src/libraries/Microsoft.Extensions.Hosting/tests/UnitTests/HostBuilderTests.cs
index 524543124033c..602d32b195738 100644
--- a/src/libraries/Microsoft.Extensions.Hosting/tests/UnitTests/HostBuilderTests.cs
+++ b/src/libraries/Microsoft.Extensions.Hosting/tests/UnitTests/HostBuilderTests.cs
@@ -644,7 +644,9 @@ public void HostServicesSameServiceProviderAsInHostBuilder()
var hostBuilder = Host.CreateDefaultBuilder();
var host = hostBuilder.Build();
- var type = hostBuilder.GetType();
+ // Use typeof so that trimming can see the field being used below
+ var type = typeof(HostBuilder);
+ Assert.Equal(hostBuilder.GetType(), type);
var field = type.GetField("_appServices", BindingFlags.Instance | BindingFlags.NonPublic)!;
var appServicesFromHostBuilder = (IServiceProvider)field.GetValue(hostBuilder)!;
Assert.Same(appServicesFromHostBuilder, host.Services);
diff --git a/src/libraries/Microsoft.Extensions.Hosting/tests/UnitTests/Internal/HostTests.cs b/src/libraries/Microsoft.Extensions.Hosting/tests/UnitTests/Internal/HostTests.cs
index b3133dba3be88..d55df715fc903 100644
--- a/src/libraries/Microsoft.Extensions.Hosting/tests/UnitTests/Internal/HostTests.cs
+++ b/src/libraries/Microsoft.Extensions.Hosting/tests/UnitTests/Internal/HostTests.cs
@@ -565,7 +565,8 @@ public async Task HostShutsDownWhenTokenTriggers()
Assert.Equal(1, service.DisposeCount);
}
- [Fact]
+ // Moq heavily utilizes RefEmit, which does not work on most aot workloads
+ [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
public async Task HostStopAsyncCanBeCancelledEarly()
{
var service = new Mock();
@@ -596,7 +597,8 @@ public async Task HostStopAsyncCanBeCancelledEarly()
}
}
- [Fact]
+ // Moq heavily utilizes RefEmit, which does not work on most aot workloads
+ [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
public async Task HostStopAsyncUsesDefaultTimeoutIfGivenTokenDoesNotFire()
{
var service = new Mock();
@@ -628,7 +630,8 @@ public async Task HostStopAsyncUsesDefaultTimeoutIfGivenTokenDoesNotFire()
}
}
- [Fact]
+ // Moq heavily utilizes RefEmit, which does not work on most aot workloads
+ [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
public async Task WebHostStopAsyncUsesDefaultTimeoutIfNoTokenProvided()
{
var service = new Mock();
@@ -1151,7 +1154,8 @@ public async Task Host_InvokesConfigureServicesMethodsOnlyOnce()
}
}
- [Fact]
+ // Moq heavily utilizes RefEmit, which does not work on most aot workloads
+ [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
public void Dispose_DisposesAppConfigurationProviders()
{
var providerMock = new Mock().As();
@@ -1175,7 +1179,8 @@ public void Dispose_DisposesAppConfigurationProviders()
providerMock.Verify(c => c.Dispose(), Times.AtLeastOnce());
}
- [Fact]
+ // Moq heavily utilizes RefEmit, which does not work on most aot workloads
+ [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
public void Dispose_DisposesHostConfigurationProviders()
{
var providerMock = new Mock().As();
@@ -1250,7 +1255,8 @@ public async Task HostCallsDisposeAsyncOnServiceProviderWhenDisposeAsyncCalled()
}
}
- [Fact]
+ // Moq heavily utilizes RefEmit, which does not work on most aot workloads
+ [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
public async Task DisposeAsync_DisposesAppConfigurationProviders()
{
var providerMock = new Mock().As();
@@ -1274,7 +1280,8 @@ public async Task DisposeAsync_DisposesAppConfigurationProviders()
providerMock.Verify(c => c.Dispose(), Times.AtLeastOnce());
}
- [Fact]
+ // Moq heavily utilizes RefEmit, which does not work on most aot workloads
+ [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
public async Task DisposeAsync_DisposesHostConfigurationProviders()
{
var providerMock = new Mock().As();
@@ -1298,7 +1305,8 @@ public async Task DisposeAsync_DisposesHostConfigurationProviders()
providerMock.Verify(c => c.Dispose(), Times.AtLeastOnce());
}
- [Fact]
+ // Moq heavily utilizes RefEmit, which does not work on most aot workloads
+ [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
public void ThrowExceptionForCustomImplementationOfIHostApplicationLifetime()
{
var hostApplicationLifetimeMock = new Mock();
diff --git a/src/libraries/Microsoft.Extensions.Logging/tests/Common/LoggerFactoryExtensionsTest.cs b/src/libraries/Microsoft.Extensions.Logging/tests/Common/LoggerFactoryExtensionsTest.cs
index ab237491568d2..7b96a62a48adf 100644
--- a/src/libraries/Microsoft.Extensions.Logging/tests/Common/LoggerFactoryExtensionsTest.cs
+++ b/src/libraries/Microsoft.Extensions.Logging/tests/Common/LoggerFactoryExtensionsTest.cs
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
+using System;
using Microsoft.Extensions.Logging.Testing;
using Moq;
using Xunit;
@@ -9,7 +10,8 @@ namespace Microsoft.Extensions.Logging.Test
{
public class LoggerFactoryExtensionsTest
{
- [Fact]
+ // Moq heavily utilizes RefEmit, which does not work on most aot workloads
+ [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/34091", TestRuntimes.Mono)]
public void LoggerFactoryCreateOfT_CallsCreateWithCorrectName()
{
@@ -28,7 +30,8 @@ public void LoggerFactoryCreateOfT_CallsCreateWithCorrectName()
factory.Verify(f => f.CreateLogger(expected));
}
- [Fact]
+ // Moq heavily utilizes RefEmit, which does not work on most aot workloads
+ [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/34091", TestRuntimes.Mono)]
public void LoggerFactoryCreateOfT_SingleGeneric_CallsCreateWithCorrectName()
{
@@ -44,7 +47,8 @@ public void LoggerFactoryCreateOfT_SingleGeneric_CallsCreateWithCorrectName()
Assert.NotNull(logger);
}
- [Fact]
+ // Moq heavily utilizes RefEmit, which does not work on most aot workloads
+ [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/34091", TestRuntimes.Mono)]
public void LoggerFactoryCreateOfT_TwoGenerics_CallsCreateWithCorrectName()
{
@@ -115,7 +119,8 @@ public void CreatesLoggerName_OnMultipleTypeArgumentGenericType_CreatesWithoutGe
}
- [Fact]
+ // Moq heavily utilizes RefEmit, which does not work on most aot workloads
+ [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/34091", TestRuntimes.Mono)]
public void LoggerFactoryCreate_CallsCreateWithCorrectName()
{
@@ -134,7 +139,8 @@ public void LoggerFactoryCreate_CallsCreateWithCorrectName()
factory.Verify(f => f.CreateLogger(expected));
}
- [Fact]
+ // Moq heavily utilizes RefEmit, which does not work on most aot workloads
+ [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/34091", TestRuntimes.Mono)]
public void LoggerFactoryCreate_SingleGeneric_CallsCreateWithCorrectName()
{
@@ -150,7 +156,8 @@ public void LoggerFactoryCreate_SingleGeneric_CallsCreateWithCorrectName()
Assert.NotNull(logger);
}
- [Fact]
+ // Moq heavily utilizes RefEmit, which does not work on most aot workloads
+ [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/34091", TestRuntimes.Mono)]
public void LoggerFactoryCreate_TwoGenerics_CallsCreateWithCorrectName()
{
diff --git a/src/libraries/Microsoft.Extensions.Logging/tests/Common/LoggerTest.cs b/src/libraries/Microsoft.Extensions.Logging/tests/Common/LoggerTest.cs
index a2a635077ae52..75bc1f25892dc 100644
--- a/src/libraries/Microsoft.Extensions.Logging/tests/Common/LoggerTest.cs
+++ b/src/libraries/Microsoft.Extensions.Logging/tests/Common/LoggerTest.cs
@@ -124,7 +124,8 @@ public void LoggerCanGetProviderAfterItIsCreated()
Assert.Equal(new[] { "provider1.Test-Hello" }, store);
}
- [Fact]
+ // Moq heavily utilizes RefEmit, which does not work on most aot workloads
+ [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsReflectionEmitSupported))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/34091", TestRuntimes.Mono)]
public void ScopesAreNotCreatedForDisabledLoggers()
{
@@ -150,7 +151,8 @@ public void ScopesAreNotCreatedForDisabledLoggers()
logger.Verify(l => l.BeginScope(It.IsAny