diff --git a/src/libraries/Common/tests/SourceGenerators/GeneratorTestHelpers.cs b/src/libraries/Common/tests/SourceGenerators/GeneratorTestHelpers.cs
index d62a3c788e73dc..1fc0fdc06ab040 100644
--- a/src/libraries/Common/tests/SourceGenerators/GeneratorTestHelpers.cs
+++ b/src/libraries/Common/tests/SourceGenerators/GeneratorTestHelpers.cs
@@ -4,6 +4,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;
using Xunit;
@@ -15,6 +16,7 @@ internal static class GeneratorTestHelpers
///
/// Asserts for structural equality, returning a path to the mismatching data when not equal.
///
+ [RequiresUnreferencedCode("Checks structural equality using reflection")]
public static void AssertStructurallyEqual(T expected, T actual)
{
CheckAreEqualCore(expected, actual, new());
diff --git a/src/libraries/Common/tests/System/Threading/Tasks/GetStateMachineData.cs b/src/libraries/Common/tests/System/Threading/Tasks/GetStateMachineData.cs
index 21f83967fb8ba8..422f3b7b831b8a 100644
--- a/src/libraries/Common/tests/System/Threading/Tasks/GetStateMachineData.cs
+++ b/src/libraries/Common/tests/System/Threading/Tasks/GetStateMachineData.cs
@@ -1,22 +1,14 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-using System.Collections.Generic;
-using System.Linq;
-using System.Reflection;
using System.Runtime.CompilerServices;
-using System.Text;
namespace System.Threading.Tasks
{
///
- /// Fragile trick for getting a description of the current state of a .NET Core async method state machine.
- /// To use, first await FetchAsync to get back an object:
+ /// Fragile trick for getting the current state of a .NET Core async method state machine.
+ /// To use, await FetchAsync to get back an object:
/// object box = await GetStateMachineData.FetchAsync();
- /// and then when the description is desired, use:
- /// string description = GetStateMachineData.Describe(box);
- /// For example:
- /// using (new Timer(s => Console.WriteLine(GetStateMachineData.Describe(s)), await GetStateMachineData.FetchAsync(), 60_000, 60_000))
///
internal sealed class GetStateMachineData : ICriticalNotifyCompletion
{
@@ -25,83 +17,6 @@ internal sealed class GetStateMachineData : ICriticalNotifyCompletion
/// Returns an awaitable whose awaited result will be the boxed state machine for the async method.
public static GetStateMachineData FetchAsync() => new GetStateMachineData();
- /// Creates a string representation of a boxed state machine object.
- public static string Describe(object box)
- {
- var sb = new StringBuilder();
- var seen = new HashSet();
- Describe(box, sb, seen, 0);
- return sb.ToString();
-
- static void Describe(object box, StringBuilder sb, HashSet seen, int indentLevel)
- {
- string indent = string.Concat(Enumerable.Repeat(" ", indentLevel));
-
- // If we were handed a null object (which should only happen from recursion),
- // state that the object was null.
- if (box is null)
- {
- sb.Append(indent).AppendLine($"(Object was null.)");
- return;
- }
-
- // If as we're walking a graph we happen upon a cycle, break it.
- if (!seen.Add(box))
- {
- sb.Append(indent).AppendLine($"(Object already seen in graph walk.)");
- return;
- }
-
- // Try to get the StateMachine field from the AsyncStateMachineBox<>. If we can't,
- // just print out the details we can and bail.
- FieldInfo stateMachineField = box.GetType().GetField("StateMachine", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
- if (stateMachineField is null)
- {
- sb.Append(indent).AppendLine($"(Couldn't get state machine field from {box}.)");
- sb.Append(indent).AppendLine(ToString(box));
- return;
- }
-
- // Get the state machine from the StateMachine field.
- IAsyncStateMachine stateMachine = stateMachineField.GetValue(box) as IAsyncStateMachine;
- if (stateMachine is null)
- {
- sb.Append(indent).AppendLine($"(Null state machine from {box}.)");
- return;
- }
-
- // Print out the name of the state machine.
- Type stateMachineType = stateMachine.GetType();
- sb.Append(indent).AppendLine(stateMachineType.FullName);
-
- // Get all of the fields on the state machine, and print them all out.
- FieldInfo[] fields = stateMachineType.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
- foreach (FieldInfo fi in fields)
- {
- // Print out the field name and its value.
- object fiValue = fi.GetValue(stateMachine);
- sb.Append(indent).AppendLine($" {fi.Name}: {ToString(fiValue)}");
-
- // If the field is an awaiter, recursively examine any tasks it directly references.
- if (fiValue is ICriticalNotifyCompletion)
- {
- foreach (FieldInfo possibleTask in fiValue.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
- {
- if (possibleTask.GetValue(fiValue) is Task awaitedTask)
- {
- Describe(awaitedTask, sb, seen, indentLevel + 1);
- }
- }
- }
- }
- }
-
- static string ToString(object value) =>
- value is null ? "(null)" :
- value is Task t ? $"Status: {t.Status}, Exception: {t.Exception?.InnerException}" :
- value.ToString();
- }
-
private GetStateMachineData() { }
public GetStateMachineData GetAwaiter() => this;
public bool IsCompleted => false;
diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/GeneratorTests.Incremental.cs b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/GeneratorTests.Incremental.cs
index bb6c5baae32272..040118111effee 100644
--- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/GeneratorTests.Incremental.cs
+++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/GeneratorTests.Incremental.cs
@@ -22,7 +22,9 @@ public async Task CompilingTheSameSourceResultsInEqualModels()
SourceGenerationSpec spec2 = (await new ConfigBindingGenTestDriver().RunGeneratorAndUpdateCompilation(BindCallSampleCode)).GenerationSpec;
Assert.NotSame(spec1, spec2);
+#pragma warning disable IL2026 // https://github.com/dotnet/runtime/issues/126862
GeneratorTestHelpers.AssertStructurallyEqual(spec1, spec2);
+#pragma warning restore IL2026
Assert.Equal(spec1, spec2);
Assert.Equal(spec1.GetHashCode(), spec2.GetHashCode());
diff --git a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Microsoft.Extensions.Configuration.Binder.SourceGeneration.Tests.csproj b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Microsoft.Extensions.Configuration.Binder.SourceGeneration.Tests.csproj
index 495f17b9749d46..a252695fd2dda9 100644
--- a/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Microsoft.Extensions.Configuration.Binder.SourceGeneration.Tests.csproj
+++ b/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Microsoft.Extensions.Configuration.Binder.SourceGeneration.Tests.csproj
@@ -22,6 +22,7 @@
+
diff --git a/src/libraries/Microsoft.Extensions.Configuration.CommandLine/tests/Microsoft.Extensions.Configuration.CommandLine.Tests.csproj b/src/libraries/Microsoft.Extensions.Configuration.CommandLine/tests/Microsoft.Extensions.Configuration.CommandLine.Tests.csproj
index 69800a8c2857f6..c50143436bfaf4 100644
--- a/src/libraries/Microsoft.Extensions.Configuration.CommandLine/tests/Microsoft.Extensions.Configuration.CommandLine.Tests.csproj
+++ b/src/libraries/Microsoft.Extensions.Configuration.CommandLine/tests/Microsoft.Extensions.Configuration.CommandLine.Tests.csproj
@@ -3,9 +3,6 @@
$(NetCoreAppCurrent);$(NetFrameworkCurrent)
true
-
- false
- false
diff --git a/src/libraries/Microsoft.Extensions.Configuration.Ini/tests/Microsoft.Extensions.Configuration.Ini.Tests.csproj b/src/libraries/Microsoft.Extensions.Configuration.Ini/tests/Microsoft.Extensions.Configuration.Ini.Tests.csproj
index 66885a90011aa3..28d3dcb8efe1fa 100644
--- a/src/libraries/Microsoft.Extensions.Configuration.Ini/tests/Microsoft.Extensions.Configuration.Ini.Tests.csproj
+++ b/src/libraries/Microsoft.Extensions.Configuration.Ini/tests/Microsoft.Extensions.Configuration.Ini.Tests.csproj
@@ -3,9 +3,6 @@
$(NetCoreAppCurrent);$(NetFrameworkCurrent)
true
-
- false
- false
diff --git a/src/libraries/Microsoft.Extensions.Configuration.Json/tests/Microsoft.Extensions.Configuration.Json.Tests.csproj b/src/libraries/Microsoft.Extensions.Configuration.Json/tests/Microsoft.Extensions.Configuration.Json.Tests.csproj
index 45433e2ff6f2bf..eef49b47827a3e 100644
--- a/src/libraries/Microsoft.Extensions.Configuration.Json/tests/Microsoft.Extensions.Configuration.Json.Tests.csproj
+++ b/src/libraries/Microsoft.Extensions.Configuration.Json/tests/Microsoft.Extensions.Configuration.Json.Tests.csproj
@@ -3,9 +3,6 @@
$(NetCoreAppCurrent);$(NetFrameworkCurrent)
true
-
- false
- false
diff --git a/src/libraries/Microsoft.Extensions.Configuration/tests/ConfigurationProviderTestBase.cs b/src/libraries/Microsoft.Extensions.Configuration/tests/ConfigurationProviderTestBase.cs
index 7a29da0f31d4c2..b8da228e475ded 100644
--- a/src/libraries/Microsoft.Extensions.Configuration/tests/ConfigurationProviderTestBase.cs
+++ b/src/libraries/Microsoft.Extensions.Configuration/tests/ConfigurationProviderTestBase.cs
@@ -130,7 +130,9 @@ public virtual void Bind_to_object()
{
var configuration = BuildConfigRoot(LoadThroughProvider(TestSection.TestConfig));
+#pragma warning disable IL2026, IL3050 // https://github.com/dotnet/runtime/issues/126862
var options = configuration.Get();
+#pragma warning restore IL2026, IL3050
Assert.Equal("Value1", options.Key1);
Assert.Equal("Value12", options.Section1.Key2);
diff --git a/src/libraries/Microsoft.Extensions.Configuration/tests/Microsoft.Extensions.Configuration.Tests.csproj b/src/libraries/Microsoft.Extensions.Configuration/tests/Microsoft.Extensions.Configuration.Tests.csproj
index f0e0bb27ea1be0..91ef2601d28568 100644
--- a/src/libraries/Microsoft.Extensions.Configuration/tests/Microsoft.Extensions.Configuration.Tests.csproj
+++ b/src/libraries/Microsoft.Extensions.Configuration/tests/Microsoft.Extensions.Configuration.Tests.csproj
@@ -2,9 +2,6 @@
$(NetCoreAppCurrent);$(NetFrameworkCurrent)
-
- false
- false
diff --git a/src/libraries/Microsoft.Extensions.DependencyInjection/tests/DI.External.Tests/Microsoft.Extensions.DependencyInjection.ExternalContainers.Tests.csproj b/src/libraries/Microsoft.Extensions.DependencyInjection/tests/DI.External.Tests/Microsoft.Extensions.DependencyInjection.ExternalContainers.Tests.csproj
index 85b40c331155e2..e809e2dac714b1 100644
--- a/src/libraries/Microsoft.Extensions.DependencyInjection/tests/DI.External.Tests/Microsoft.Extensions.DependencyInjection.ExternalContainers.Tests.csproj
+++ b/src/libraries/Microsoft.Extensions.DependencyInjection/tests/DI.External.Tests/Microsoft.Extensions.DependencyInjection.ExternalContainers.Tests.csproj
@@ -4,8 +4,6 @@
$(NetCoreAppCurrent);$(NetFrameworkCurrent)
true
$(NoWarn);CS8002
-
- false
diff --git a/src/libraries/Microsoft.Extensions.DependencyInjection/tests/DI.External.Tests/SkippableDependencyInjectionSpecificationTests.cs b/src/libraries/Microsoft.Extensions.DependencyInjection/tests/DI.External.Tests/SkippableDependencyInjectionSpecificationTests.cs
index d0d01910712040..8a229f5bc3d575 100644
--- a/src/libraries/Microsoft.Extensions.DependencyInjection/tests/DI.External.Tests/SkippableDependencyInjectionSpecificationTests.cs
+++ b/src/libraries/Microsoft.Extensions.DependencyInjection/tests/DI.External.Tests/SkippableDependencyInjectionSpecificationTests.cs
@@ -16,7 +16,12 @@ protected sealed override IServiceProvider CreateServiceProvider(IServiceCollect
{
foreach (var stackFrame in new StackTrace(1).GetFrames().Take(2))
{
- if (SkippedTests.Contains(stackFrame.GetMethod().Name))
+#if NET
+ var methodName = DiagnosticMethodInfo.Create(stackFrame)?.Name;
+#else
+ var methodName = stackFrame.GetMethod()?.Name;
+#endif
+ if (SkippedTests.Contains(methodName))
{
// We skip tests by returning MEDI service provider that we know passes the test
return serviceCollection.BuildServiceProvider();
diff --git a/src/libraries/System.DirectoryServices/tests/System.DirectoryServices.Tests.csproj b/src/libraries/System.DirectoryServices/tests/System.DirectoryServices.Tests.csproj
index e350bacc3b355f..6b6fb4db2a5f69 100644
--- a/src/libraries/System.DirectoryServices/tests/System.DirectoryServices.Tests.csproj
+++ b/src/libraries/System.DirectoryServices/tests/System.DirectoryServices.Tests.csproj
@@ -3,8 +3,6 @@
$(NoWarn);SYSLIB0003
$(NetCoreAppCurrent)-windows;$(NetFrameworkCurrent)
-
- false
diff --git a/src/libraries/System.DirectoryServices/tests/System/DirectoryServices/DirectoryServicesTests.cs b/src/libraries/System.DirectoryServices/tests/System/DirectoryServices/DirectoryServicesTests.cs
index 5cf652ca1b6b28..f4a256257ffa18 100644
--- a/src/libraries/System.DirectoryServices/tests/System/DirectoryServices/DirectoryServicesTests.cs
+++ b/src/libraries/System.DirectoryServices/tests/System/DirectoryServices/DirectoryServicesTests.cs
@@ -1,12 +1,12 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-using System.Runtime.InteropServices;
-using System.Collections.Generic;
using System.Collections;
+using System.Collections.Generic;
+using System.Reflection;
+using System.Runtime.InteropServices;
using Xunit;
using Xunit.Sdk;
-using System.Reflection;
namespace System.DirectoryServices.Tests
{
@@ -18,7 +18,9 @@ public partial class DirectoryServicesTests
[Fact]
public void TestGetAllTypes()
{
+#pragma warning disable IL2026 // Test validates Assembly.GetTypes in an untrimmed test build.
Type[] allTypes = typeof(DirectoryEntry).Assembly.GetTypes();
+#pragma warning restore IL2026
Assert.Contains(typeof(DirectoryEntry), allTypes);
}
diff --git a/src/libraries/System.IO.Packaging/tests/PartPieceTests.cs b/src/libraries/System.IO.Packaging/tests/PartPieceTests.cs
index 5069380acc6260..37736f4d6d7f6f 100644
--- a/src/libraries/System.IO.Packaging/tests/PartPieceTests.cs
+++ b/src/libraries/System.IO.Packaging/tests/PartPieceTests.cs
@@ -284,7 +284,9 @@ public void OutOfOrderPartPiecesAreParsable(string partPieceLists, int expectedC
using var zipArchive = new ZipArchive(ms, ZipArchiveMode.Read);
string[] archiveNames = partPieceLists.Split(',');
+#pragma warning disable IL3050 // s_ZipPackagePartPieceType is a reference type, this is safe to suppress
Type genericSortedSetType = typeof(SortedSet<>).MakeGenericType(s_ZipPackagePartPieceType);
+#pragma warning restore IL3050
MethodInfo sortedSetAddMethod = genericSortedSetType.GetMethod("Add");
PropertyInfo zipPackagePartPieceNumberProperty = s_ZipPackagePartPieceType.GetProperty("PieceNumber", BindingFlags.NonPublic | BindingFlags.Instance);
System.Collections.IEnumerable partPieces = (System.Collections.IEnumerable)Activator.CreateInstance(genericSortedSetType);
diff --git a/src/libraries/System.IO.Packaging/tests/System.IO.Packaging.Tests.csproj b/src/libraries/System.IO.Packaging/tests/System.IO.Packaging.Tests.csproj
index d01759d746cb6c..90f1554700b357 100644
--- a/src/libraries/System.IO.Packaging/tests/System.IO.Packaging.Tests.csproj
+++ b/src/libraries/System.IO.Packaging/tests/System.IO.Packaging.Tests.csproj
@@ -1,8 +1,6 @@
$(NetCoreAppCurrent);$(NetFrameworkCurrent)
-
- false
diff --git a/src/libraries/System.Management/tests/System.Management.Tests.csproj b/src/libraries/System.Management/tests/System.Management.Tests.csproj
index 8d7d8b39d30586..ad44bb1733676b 100644
--- a/src/libraries/System.Management/tests/System.Management.Tests.csproj
+++ b/src/libraries/System.Management/tests/System.Management.Tests.csproj
@@ -1,9 +1,6 @@
$(NetCoreAppCurrent)-windows;$(NetFrameworkCurrent)
-
- false
- false
diff --git a/src/libraries/System.Management/tests/System/Management/ManagementObjectTests.cs b/src/libraries/System.Management/tests/System/Management/ManagementObjectTests.cs
index ccf8154335a87d..490d31fd303943 100644
--- a/src/libraries/System.Management/tests/System/Management/ManagementObjectTests.cs
+++ b/src/libraries/System.Management/tests/System/Management/ManagementObjectTests.cs
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
using System.Diagnostics;
+using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using Microsoft.DotNet.XUnitExtensions;
@@ -105,6 +106,10 @@ public void Invoke_Instance_And_Static_Method_Win32_Process()
[ConditionalFact(typeof(WmiTestHelper), nameof(WmiTestHelper.IsWmiSupported))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/34689", TestPlatforms.Windows, TargetFrameworkMonikers.Netcoreapp, TestRuntimes.Mono)]
[OuterLoop]
+#if NET
+ [RequiresDynamicCode("BinaryFormatter serialization uses dynamic code generation")]
+ [RequiresUnreferencedCode("BinaryFormatter serialization is not trim compatible")]
+#endif
public void Serialize_ManagementException()
{
try
diff --git a/src/libraries/System.Net.Http.WinHttpHandler/tests/UnitTests/FakeMarshal.cs b/src/libraries/System.Net.Http.WinHttpHandler/tests/UnitTests/FakeMarshal.cs
index 10aa7480de9774..a4593563099fca 100644
--- a/src/libraries/System.Net.Http.WinHttpHandler/tests/UnitTests/FakeMarshal.cs
+++ b/src/libraries/System.Net.Http.WinHttpHandler/tests/UnitTests/FakeMarshal.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.Diagnostics.CodeAnalysis;
using System.Net.Http.WinHttpHandlerUnitTests;
namespace System.Net.Http
@@ -52,7 +53,8 @@ public static IntPtr UnsafeAddrOfPinnedArrayElement(T[] arr, int index)
return System.Runtime.InteropServices.Marshal.UnsafeAddrOfPinnedArrayElement(arr, index);
}
- public static T PtrToStructure(IntPtr ptr)
+ public static T PtrToStructure<
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] T>(IntPtr ptr)
{
return System.Runtime.InteropServices.Marshal.PtrToStructure(ptr);
}
diff --git a/src/libraries/System.Net.Http.WinHttpHandler/tests/UnitTests/System.Net.Http.WinHttpHandler.Unit.Tests.csproj b/src/libraries/System.Net.Http.WinHttpHandler/tests/UnitTests/System.Net.Http.WinHttpHandler.Unit.Tests.csproj
index 10c5a92561a0e1..edabede4649558 100644
--- a/src/libraries/System.Net.Http.WinHttpHandler/tests/UnitTests/System.Net.Http.WinHttpHandler.Unit.Tests.csproj
+++ b/src/libraries/System.Net.Http.WinHttpHandler/tests/UnitTests/System.Net.Http.WinHttpHandler.Unit.Tests.csproj
@@ -5,8 +5,6 @@
..\..\src\Resources\Strings.resx
$(NetCoreAppCurrent)-windows
$(DefineConstants);UNITTEST
-
- false
diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/Watchdog.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/Watchdog.cs
index 0efadfc3e1bfd7..09dbbd07aad87f 100644
--- a/src/libraries/System.Net.Http/tests/FunctionalTests/Watchdog.cs
+++ b/src/libraries/System.Net.Http/tests/FunctionalTests/Watchdog.cs
@@ -2,9 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
using System;
-using System.Collections.Generic;
using System.Runtime.CompilerServices;
-using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Xunit;
@@ -13,7 +11,7 @@ namespace System.Net.Http.Functional.Tests
{
///
/// This is using similar trick to GetStateMachineData
- /// If marked test runs for more than 60s it will print machine state and make sure it fails
+ /// If marked test runs for more than 60s it will make sure it fails
/// Usage (await MUST be run directly in the test, should not be called from other async method):
/// using (await Watchdog.CreateAsync())
/// {
@@ -30,7 +28,7 @@ public static Watchdog CreateAsync()
=> new Watchdog();
public IDisposable GetResult()
- => new WatchdogImpl(_box);
+ => new WatchdogImpl();
public Watchdog GetAwaiter() => this;
public bool IsCompleted => false;
@@ -46,14 +44,13 @@ private class WatchdogImpl : IDisposable
private bool _passed = true;
private Timer _timer;
- public WatchdogImpl(object stateMachineData)
+ public WatchdogImpl()
{
- _timer = new Timer(s =>
+ _timer = new Timer(_ =>
{
_passed = false;
- Console.WriteLine(GetStateMachineData.Describe(s));
},
- stateMachineData,
+ null,
60_000,
60_000);
}
diff --git a/src/libraries/System.Net.Mail/tests/Functional/MailMessageTest.cs b/src/libraries/System.Net.Mail/tests/Functional/MailMessageTest.cs
index 702d51195beb43..b3d3d89e77aa26 100644
--- a/src/libraries/System.Net.Mail/tests/Functional/MailMessageTest.cs
+++ b/src/libraries/System.Net.Mail/tests/Functional/MailMessageTest.cs
@@ -264,10 +264,12 @@ private static (string Raw, string Attachment) DecodeSentMailMessage(MailMessage
var syncSendAdapterType = Type.GetType("System.Net.SyncReadWriteAdapter, System.Net.Mail");
// Send the message.
+#pragma warning disable IL3050 // Roslyn analyzer can't see through the private reflection, but publish process can. This is safe.
typeof(MailMessage)
.GetMethod("SendAsync", BindingFlags.Instance | BindingFlags.NonPublic)
.MakeGenericMethod(syncSendAdapterType)
.Invoke(mail, new object[] { mailWriter, true, true, CancellationToken.None });
+#pragma warning restore IL3050
// Decode contents.
string result = Encoding.UTF8.GetString(stream.ToArray());
diff --git a/src/libraries/System.Net.Mail/tests/Functional/System.Net.Mail.Functional.Tests.csproj b/src/libraries/System.Net.Mail/tests/Functional/System.Net.Mail.Functional.Tests.csproj
index 74c4b3dd6d1474..fd923d17919c92 100644
--- a/src/libraries/System.Net.Mail/tests/Functional/System.Net.Mail.Functional.Tests.csproj
+++ b/src/libraries/System.Net.Mail/tests/Functional/System.Net.Mail.Functional.Tests.csproj
@@ -5,8 +5,6 @@
true
true
true
-
- false
diff --git a/src/libraries/System.Net.Quic/tests/FunctionalTests/MsQuicInteropTests.cs b/src/libraries/System.Net.Quic/tests/FunctionalTests/MsQuicInteropTests.cs
index 91838d8fab32ac..4f9f7d8c083459 100644
--- a/src/libraries/System.Net.Quic/tests/FunctionalTests/MsQuicInteropTests.cs
+++ b/src/libraries/System.Net.Quic/tests/FunctionalTests/MsQuicInteropTests.cs
@@ -3,11 +3,12 @@
using System;
using System.Diagnostics;
+using System.Diagnostics.CodeAnalysis;
+using System.Linq;
using System.Net.Security;
-using System.Threading.Tasks;
-using System.Runtime.InteropServices;
using System.Reflection;
-using System.Linq;
+using System.Runtime.InteropServices;
+using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;
@@ -17,23 +18,24 @@ namespace System.Net.Quic.Tests
{
public class MsQuicInteropTests
{
- private static MemberInfo[] GetMembers()
- {
- var members = typeof(T).FindMembers(MemberTypes.Field | MemberTypes.Property, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public, (mi, _) =>
- {
- if (mi is PropertyInfo property && property.GetSetMethod() == null)
- {
- return false;
- }
+ private const DynamicallyAccessedMemberTypes FieldsAndProperties =
+ DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields |
+ DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.NonPublicProperties;
+ private const BindingFlags InstanceMembers = BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public;
- return true;
- }, null);
+ private static MemberInfo[] GetMembers<
+ [DynamicallyAccessedMembers(FieldsAndProperties)] T>()
+ {
+ var members = typeof(T).GetFields(InstanceMembers).Cast()
+ .Concat(typeof(T).GetProperties(InstanceMembers).Where(property => property.GetSetMethod() is not null))
+ .ToArray();
Assert.NotEmpty(members);
return members;
}
+ [RequiresUnreferencedCode("Resets members using reflection")]
private static void ResetMember(MemberInfo member, object instance)
{
switch (member)
@@ -66,7 +68,9 @@ public void QuicSettings_Equals_RespectsAllMembers()
{
// copy and box the instance because reflection methods take a reference type arg
object boxed = settings;
+#pragma warning disable IL2026 // https://github.com/dotnet/runtime/issues/126862
ResetMember(member, boxed);
+#pragma warning restore IL2026
Assert.False(settings.Equals((QUIC_SETTINGS)boxed), $"Member {member.Name} is not compared.");
}
}
diff --git a/src/libraries/System.Net.Quic/tests/FunctionalTests/System.Net.Quic.Functional.Tests.csproj b/src/libraries/System.Net.Quic/tests/FunctionalTests/System.Net.Quic.Functional.Tests.csproj
index 2d1f2b08291682..29cacbc56ddffe 100644
--- a/src/libraries/System.Net.Quic/tests/FunctionalTests/System.Net.Quic.Functional.Tests.csproj
+++ b/src/libraries/System.Net.Quic/tests/FunctionalTests/System.Net.Quic.Functional.Tests.csproj
@@ -5,8 +5,6 @@
$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-linux;$(NetCoreAppCurrent)-osx
true
../../src/Resources/Strings.resx
-
- false
diff --git a/src/libraries/System.Net.Security/tests/FunctionalTests/SslStreamNegotiatedCipherSuiteTest.cs b/src/libraries/System.Net.Security/tests/FunctionalTests/SslStreamNegotiatedCipherSuiteTest.cs
index 0aa47a3a2764e5..60d1bf83fd8724 100644
--- a/src/libraries/System.Net.Security/tests/FunctionalTests/SslStreamNegotiatedCipherSuiteTest.cs
+++ b/src/libraries/System.Net.Security/tests/FunctionalTests/SslStreamNegotiatedCipherSuiteTest.cs
@@ -577,7 +577,7 @@ private static IEnumerable GetTls10And11CipherSuites()
private static IEnumerable GetNonTls13CipherSuites()
{
var tls13cs = new HashSet(GetTls13CipherSuites());
- foreach (TlsCipherSuite cs in typeof(TlsCipherSuite).GetEnumValues())
+ foreach (TlsCipherSuite cs in Enum.GetValues())
{
if (!tls13cs.Contains(cs))
{
diff --git a/src/libraries/System.Net.Security/tests/FunctionalTests/System.Net.Security.Tests.csproj b/src/libraries/System.Net.Security/tests/FunctionalTests/System.Net.Security.Tests.csproj
index e8c82b958c5b6b..79610468fe7995 100644
--- a/src/libraries/System.Net.Security/tests/FunctionalTests/System.Net.Security.Tests.csproj
+++ b/src/libraries/System.Net.Security/tests/FunctionalTests/System.Net.Security.Tests.csproj
@@ -6,8 +6,6 @@
true
true
true
-
- false
diff --git a/src/libraries/System.Net.WebProxy/tests/System.Net.WebProxy.Tests.csproj b/src/libraries/System.Net.WebProxy/tests/System.Net.WebProxy.Tests.csproj
index 2084e9062abc16..b4667242cfd3ba 100644
--- a/src/libraries/System.Net.WebProxy/tests/System.Net.WebProxy.Tests.csproj
+++ b/src/libraries/System.Net.WebProxy/tests/System.Net.WebProxy.Tests.csproj
@@ -1,8 +1,6 @@
$(NetCoreAppCurrent)
-
- false
diff --git a/src/libraries/System.Net.WebProxy/tests/WebProxyTest.cs b/src/libraries/System.Net.WebProxy/tests/WebProxyTest.cs
index c5dcd5af0e15a8..47117ece4b94f6 100644
--- a/src/libraries/System.Net.WebProxy/tests/WebProxyTest.cs
+++ b/src/libraries/System.Net.WebProxy/tests/WebProxyTest.cs
@@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
+using System.Linq;
using System.Net.NetworkInformation;
using System.Net.Sockets;
using Xunit;
@@ -44,7 +45,7 @@ public static void WebProxy_Ctor_ExpectedPropertyValues(
Assert.Equal(useDefaultCredentials, p.UseDefaultCredentials);
Assert.Equal(bypassLocal, p.BypassProxyOnLocal);
Assert.Equal(bypassedAddresses, p.BypassList);
- Assert.Equal(bypassedAddresses, (string[])p.BypassArrayList.ToArray(typeof(string)));
+ Assert.Equal(bypassedAddresses, p.BypassArrayList.Cast().ToArray());
Assert.Equal(creds, p.Credentials);
}
@@ -60,12 +61,12 @@ public static void WebProxy_BypassList_Roundtrip()
strings = new string[] { "hello", "world" };
p.BypassList = strings;
Assert.Equal(strings, p.BypassList);
- Assert.Equal(strings, (string[])p.BypassArrayList.ToArray(typeof(string)));
+ Assert.Equal(strings, p.BypassArrayList.Cast().ToArray());
strings = new string[] { "hello" };
p.BypassList = strings;
Assert.Equal(strings, p.BypassList);
- Assert.Equal(strings, (string[])p.BypassArrayList.ToArray(typeof(string)));
+ Assert.Equal(strings, p.BypassArrayList.Cast().ToArray());
strings = null;
p.BypassList = strings;
diff --git a/src/libraries/System.Net.WebSockets.Client/tests/CloseTest.Loopback.cs b/src/libraries/System.Net.WebSockets.Client/tests/CloseTest.Loopback.cs
index 66eb8a53715a20..7388cdde9e2619 100644
--- a/src/libraries/System.Net.WebSockets.Client/tests/CloseTest.Loopback.cs
+++ b/src/libraries/System.Net.WebSockets.Client/tests/CloseTest.Loopback.cs
@@ -146,7 +146,9 @@ public async Task CloseHandshake_ExceptionsAreObserved()
{
await RemoteExecutor.Invoke(static (typeName) =>
{
+#pragma warning disable IL2026, IL2072 // https://github.com/dotnet/runtime/issues/126862
ClientWebSocketTestBase test = (ClientWebSocketTestBase)Activator.CreateInstance(typeof(ClientWebSocketTestBase).Assembly.GetType(typeName), new object[] { null });
+#pragma warning restore IL2026, IL2072
using CancellationTokenSource timeoutCts = new CancellationTokenSource(TimeOutMilliseconds);
Exception unobserved = null;
diff --git a/src/libraries/System.Net.WebSockets.Client/tests/System.Net.WebSockets.Client.Tests.csproj b/src/libraries/System.Net.WebSockets.Client/tests/System.Net.WebSockets.Client.Tests.csproj
index 9e3e7692fb3089..83cf148c6a9fd6 100644
--- a/src/libraries/System.Net.WebSockets.Client/tests/System.Net.WebSockets.Client.Tests.csproj
+++ b/src/libraries/System.Net.WebSockets.Client/tests/System.Net.WebSockets.Client.Tests.csproj
@@ -8,8 +8,6 @@
$(DefineConstants);NETSTANDARD
$(NoWarn);xUnit1015
-
- false
diff --git a/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/CodeSnippets.cs b/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/CodeSnippets.cs
index ad68b2dfb5761e..6d00dee71f5a9f 100644
--- a/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/CodeSnippets.cs
+++ b/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/CodeSnippets.cs
@@ -416,6 +416,7 @@ partial interface INativeAPI
{{_attributeProvider.AdditionalUserRequiredInterfaces("INativeAPI")}}
""";
+#pragma warning disable IL2057 // https://github.com/dotnet/runtime/issues/126862
public string BasicReturnTypeCustomExceptionHandling(string typeName, string customExceptionType, string preDeclaration = "") => $$"""
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@@ -431,6 +432,7 @@ partial interface INativeAPI
}
{{_attributeProvider.AdditionalUserRequiredInterfaces("INativeAPI")}}
""";
+#pragma warning restore IL2057
public string DerivedComInterfaceTypeWithShadowingMethod => $$"""
using System.Runtime.CompilerServices;
diff --git a/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/ComInterfaceGenerator.Unit.Tests.csproj b/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/ComInterfaceGenerator.Unit.Tests.csproj
index 352dc16632dd33..9ce73c44b35c9e 100644
--- a/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/ComInterfaceGenerator.Unit.Tests.csproj
+++ b/src/libraries/System.Runtime.InteropServices/tests/ComInterfaceGenerator.Unit.Tests/ComInterfaceGenerator.Unit.Tests.csproj
@@ -7,8 +7,6 @@
enable
true
../../gen/Common/Resources/Strings.resx
-
- false
diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.ComDisabled.UnitTests/System.Runtime.InteropServices.ComDisabled.Tests.csproj b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.ComDisabled.UnitTests/System.Runtime.InteropServices.ComDisabled.Tests.csproj
index 8831526b3d94f9..d54fcd8a3e9ae9 100644
--- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.ComDisabled.UnitTests/System.Runtime.InteropServices.ComDisabled.Tests.csproj
+++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.ComDisabled.UnitTests/System.Runtime.InteropServices.ComDisabled.Tests.csproj
@@ -5,8 +5,6 @@
true
true
-
- false
diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.ComDisabled.UnitTests/System/Runtime/InteropServices/Marshal/MarshalComDisabledTests.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.ComDisabled.UnitTests/System/Runtime/InteropServices/Marshal/MarshalComDisabledTests.cs
index 6eb082e9b424d3..bbc9722b0421c5 100644
--- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.ComDisabled.UnitTests/System/Runtime/InteropServices/Marshal/MarshalComDisabledTests.cs
+++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.ComDisabled.UnitTests/System/Runtime/InteropServices/Marshal/MarshalComDisabledTests.cs
@@ -151,7 +151,9 @@ public void GetObjectsForNativeVariants_T_ThrowsNotSupportedException()
[Fact]
public void BindToMoniker_ThrowsNotSupportedException()
{
+#pragma warning disable IL2026 // With COM disabled, this always throws so it's safe
Assert.Throws(() => Marshal.BindToMoniker("test"));
+#pragma warning restore IL2026
}
[Fact]
diff --git a/src/libraries/System.Runtime.Serialization.Primitives/tests/System.Runtime.Serialization.Primitives.Tests.csproj b/src/libraries/System.Runtime.Serialization.Primitives/tests/System.Runtime.Serialization.Primitives.Tests.csproj
index 3b807fd636ac13..bef1cc634e6373 100644
--- a/src/libraries/System.Runtime.Serialization.Primitives/tests/System.Runtime.Serialization.Primitives.Tests.csproj
+++ b/src/libraries/System.Runtime.Serialization.Primitives/tests/System.Runtime.Serialization.Primitives.Tests.csproj
@@ -1,9 +1,6 @@
$(NetCoreAppCurrent)
-
- false
- false
diff --git a/src/libraries/System.Runtime.Serialization.Primitives/tests/System/Runtime/Serialization/InvalidDataContractExceptionTests.cs b/src/libraries/System.Runtime.Serialization.Primitives/tests/System/Runtime/Serialization/InvalidDataContractExceptionTests.cs
index 57a4d5ac54f4e8..396ecd9fde95aa 100644
--- a/src/libraries/System.Runtime.Serialization.Primitives/tests/System/Runtime/Serialization/InvalidDataContractExceptionTests.cs
+++ b/src/libraries/System.Runtime.Serialization.Primitives/tests/System/Runtime/Serialization/InvalidDataContractExceptionTests.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.Diagnostics.CodeAnalysis;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using Xunit;
@@ -37,6 +38,8 @@ public void Ctor_String_Exception(string message)
}
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBinaryFormatterSupported))]
+ [RequiresDynamicCode("BinaryFormatter serialization uses dynamic code generation")]
+ [RequiresUnreferencedCode("BinaryFormatter serialization is not trim compatible")]
public void Ctor_SerializationInfo_StreamingContext()
{
using (var memoryStream = new MemoryStream())
diff --git a/src/libraries/System.Runtime/tests/System.Buffers.Tests/ArrayPool/CollectionTests.cs b/src/libraries/System.Runtime/tests/System.Buffers.Tests/ArrayPool/CollectionTests.cs
index e6f446fe7c8d80..528d733d026640 100644
--- a/src/libraries/System.Runtime/tests/System.Buffers.Tests/ArrayPool/CollectionTests.cs
+++ b/src/libraries/System.Runtime/tests/System.Buffers.Tests/ArrayPool/CollectionTests.cs
@@ -92,7 +92,9 @@ public unsafe void ThreadLocalIsCollectedUnderHighPressure()
const int AllocSize = 1024 * 1024 * 64;
int PageSize = Environment.SystemPageSize;
+#pragma warning disable IL2075 // This private reflection is broken since .NET 6: https://github.com/dotnet/runtime/issues/128431
var pressureMethod = ArrayPool.Shared.GetType().GetMethod("GetMemoryPressure", BindingFlags.Static | BindingFlags.NonPublic);
+#pragma warning restore IL2075
do
{
Span native = new Span(Marshal.AllocHGlobal(AllocSize).ToPointer(), AllocSize);
diff --git a/src/libraries/System.Runtime/tests/System.Buffers.Tests/System.Buffers.Tests.csproj b/src/libraries/System.Runtime/tests/System.Buffers.Tests/System.Buffers.Tests.csproj
index 39828a91ff6d9a..113d56e6f43635 100644
--- a/src/libraries/System.Runtime/tests/System.Buffers.Tests/System.Buffers.Tests.csproj
+++ b/src/libraries/System.Runtime/tests/System.Buffers.Tests/System.Buffers.Tests.csproj
@@ -4,8 +4,6 @@
true
true
$(NetCoreAppCurrent)
-
- false
true
diff --git a/src/libraries/System.Runtime/tests/System.Reflection.Tests/CoreCLR/AssemblyTests.cs b/src/libraries/System.Runtime/tests/System.Reflection.Tests/CoreCLR/AssemblyTests.cs
index 7d76478b716965..0c305dfc0a0543 100644
--- a/src/libraries/System.Runtime/tests/System.Reflection.Tests/CoreCLR/AssemblyTests.cs
+++ b/src/libraries/System.Runtime/tests/System.Reflection.Tests/CoreCLR/AssemblyTests.cs
@@ -34,8 +34,10 @@ public void LoadFromStream_EmptyStream_ThrowsBadImageFormatException()
{
using (var emptyStream = new MemoryStream())
{
+#pragma warning disable IL2026 // https://github.com/dotnet/runtime/issues/126862
BadImageFormatException ex = Assert.Throws(
() => AssemblyLoadContext.Default.LoadFromStream(emptyStream));
+#pragma warning restore IL2026
Assert.Contains("empty", ex.Message, StringComparison.OrdinalIgnoreCase);
}
}
@@ -54,7 +56,9 @@ private sealed class TestStreamLoadContext : AssemblyLoadContext
{
protected override Assembly Load(AssemblyName assemblyName)
{
+#pragma warning disable IL2026 // https://github.com/dotnet/runtime/issues/126862
return LoadFromStream(GetExecutingAssembly().GetManifestResourceStream(assemblyName.Name + ".dll"));
+#pragma warning restore IL2026
}
}
}
diff --git a/src/libraries/System.Runtime/tests/System.Reflection.Tests/CoreCLR/System.Reflection.CoreCLR.Tests.csproj b/src/libraries/System.Runtime/tests/System.Reflection.Tests/CoreCLR/System.Reflection.CoreCLR.Tests.csproj
index ac2edc0f775ab5..ea0343e7811d73 100644
--- a/src/libraries/System.Runtime/tests/System.Reflection.Tests/CoreCLR/System.Reflection.CoreCLR.Tests.csproj
+++ b/src/libraries/System.Runtime/tests/System.Reflection.Tests/CoreCLR/System.Reflection.CoreCLR.Tests.csproj
@@ -2,8 +2,6 @@
$(NetCoreAppCurrent)
true
-
- false
diff --git a/src/libraries/System.Runtime/tests/System.Runtime.InteropServices.RuntimeInformation.Tests/DescriptionNameTests.cs b/src/libraries/System.Runtime/tests/System.Runtime.InteropServices.RuntimeInformation.Tests/DescriptionNameTests.cs
index 06fde72490a7a5..0bbc490fe98909 100644
--- a/src/libraries/System.Runtime/tests/System.Runtime.InteropServices.RuntimeInformation.Tests/DescriptionNameTests.cs
+++ b/src/libraries/System.Runtime/tests/System.Runtime.InteropServices.RuntimeInformation.Tests/DescriptionNameTests.cs
@@ -103,7 +103,9 @@ public void DumpRuntimeInformationToConsole()
sb.Append($"###\t{prop}: ");
try
{
+#pragma warning disable IL2075 // Not used for testing, just informational logging
sb.Append(p.GetType().GetProperty(prop).GetValue(p));
+#pragma warning restore IL2075
}
catch (Exception e)
{
diff --git a/src/libraries/System.Runtime/tests/System.Runtime.InteropServices.RuntimeInformation.Tests/System.Runtime.InteropServices.RuntimeInformation.Tests.csproj b/src/libraries/System.Runtime/tests/System.Runtime.InteropServices.RuntimeInformation.Tests/System.Runtime.InteropServices.RuntimeInformation.Tests.csproj
index 25dbbb548cd920..b21850df267dfa 100644
--- a/src/libraries/System.Runtime/tests/System.Runtime.InteropServices.RuntimeInformation.Tests/System.Runtime.InteropServices.RuntimeInformation.Tests.csproj
+++ b/src/libraries/System.Runtime/tests/System.Runtime.InteropServices.RuntimeInformation.Tests/System.Runtime.InteropServices.RuntimeInformation.Tests.csproj
@@ -3,8 +3,6 @@
true
true
$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-unix;$(NetCoreAppCurrent)-browser
-
- false
$(DefineConstants);STABILIZE_PACKAGE_VERSION
diff --git a/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Reflection/BindingFlagsDoNotWrap.cs b/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Reflection/BindingFlagsDoNotWrap.cs
index 0bebd1c99c97f4..8426abc8cff149 100644
--- a/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Reflection/BindingFlagsDoNotWrap.cs
+++ b/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Reflection/BindingFlagsDoNotWrap.cs
@@ -133,7 +133,9 @@ public static void AssemblyCreateInstance()
{
Assembly a = typeof(TestClass).Assembly;
const BindingFlags flags = BindingFlags.Public | BindingFlags.Instance;
+#pragma warning disable IL2058 // https://github.com/dotnet/runtime/issues/126862
TestDoNotWrap((bf) => a.CreateInstance(typeof(TestClass).FullName, false, bf | flags, null, Array.Empty(), null, null));
+#pragma warning restore IL2058
}
[Fact]
@@ -141,7 +143,9 @@ public static void AssemblyCreateInstance_BadCCtor()
{
Assembly a = typeof(TestClass).Assembly;
const BindingFlags flags = BindingFlags.Public | BindingFlags.Instance;
+#pragma warning disable IL2058 // https://github.com/dotnet/runtime/issues/126862
TestDoNotWrap((bf) => a.CreateInstance(typeof(TestClassBadCCtor).FullName, false, bf | flags, null, Array.Empty(), null, null));
+#pragma warning restore IL2058
}
private static void TestDoNotWrap(Action action) where T : Exception
diff --git a/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Reflection/InvokeEmit/System.Runtime.ReflectionInvokeEmit.Tests.csproj b/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Reflection/InvokeEmit/System.Runtime.ReflectionInvokeEmit.Tests.csproj
index c64c1e3a1e55b9..4188e399626e99 100644
--- a/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Reflection/InvokeEmit/System.Runtime.ReflectionInvokeEmit.Tests.csproj
+++ b/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Reflection/InvokeEmit/System.Runtime.ReflectionInvokeEmit.Tests.csproj
@@ -4,8 +4,6 @@
true
true
$(NetCoreAppCurrent)
-
- false
diff --git a/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Reflection/InvokeInterpreted/System.Runtime.ReflectionInvokeInterpreted.Tests.csproj b/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Reflection/InvokeInterpreted/System.Runtime.ReflectionInvokeInterpreted.Tests.csproj
index c64c1e3a1e55b9..4188e399626e99 100644
--- a/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Reflection/InvokeInterpreted/System.Runtime.ReflectionInvokeInterpreted.Tests.csproj
+++ b/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Reflection/InvokeInterpreted/System.Runtime.ReflectionInvokeInterpreted.Tests.csproj
@@ -4,8 +4,6 @@
true
true
$(NetCoreAppCurrent)
-
- false
diff --git a/src/libraries/System.Runtime/tests/System.Threading.Tasks.Extensions.Tests/System.Threading.Tasks.Extensions.Tests.csproj b/src/libraries/System.Runtime/tests/System.Threading.Tasks.Extensions.Tests/System.Threading.Tasks.Extensions.Tests.csproj
index 952e5ec237e5da..44cf712d71c7c2 100644
--- a/src/libraries/System.Runtime/tests/System.Threading.Tasks.Extensions.Tests/System.Threading.Tasks.Extensions.Tests.csproj
+++ b/src/libraries/System.Runtime/tests/System.Threading.Tasks.Extensions.Tests/System.Threading.Tasks.Extensions.Tests.csproj
@@ -3,8 +3,6 @@
$(NetCoreAppCurrent)
true
true
-
- false
diff --git a/src/libraries/System.Security.Cryptography.Pkcs/tests/CmsRecipientCollectionTests.cs b/src/libraries/System.Security.Cryptography.Pkcs/tests/CmsRecipientCollectionTests.cs
index 8589a09c81186e..54faeaf69b8432 100644
--- a/src/libraries/System.Security.Cryptography.Pkcs/tests/CmsRecipientCollectionTests.cs
+++ b/src/libraries/System.Security.Cryptography.Pkcs/tests/CmsRecipientCollectionTests.cs
@@ -172,7 +172,9 @@ public static void CopyExceptions()
if (PlatformDetection.IsNonZeroLowerBoundArraySupported)
{
// Array has non-zero lower bound
+#pragma warning disable IL3050 // Creating multi-dimensional arrays is AOT safe, only SzArrays are problem
Array array = Array.CreateInstance(typeof(object), new int[] { 10 }, new int[] { 10 });
+#pragma warning restore IL3050
Assert.Throws(() => ic.CopyTo(array, 0));
}
}
diff --git a/src/libraries/System.Security.Cryptography.Pkcs/tests/CryptographicAttributeObjectCollectionTests.cs b/src/libraries/System.Security.Cryptography.Pkcs/tests/CryptographicAttributeObjectCollectionTests.cs
index eb58a7e43a5eec..68e6f5ef062949 100644
--- a/src/libraries/System.Security.Cryptography.Pkcs/tests/CryptographicAttributeObjectCollectionTests.cs
+++ b/src/libraries/System.Security.Cryptography.Pkcs/tests/CryptographicAttributeObjectCollectionTests.cs
@@ -164,7 +164,9 @@ public static void CopyExceptions()
if (PlatformDetection.IsNonZeroLowerBoundArraySupported)
{
// Array has non-zero lower bound
+#pragma warning disable IL3050 // Creating multi-dimensional arrays is AOT safe, only SzArrays are problem
Array array = Array.CreateInstance(typeof(object), new int[] { 10 }, new int[] { 10 });
+#pragma warning restore IL3050
Assert.Throws(() => ic.CopyTo(array, 0));
}
}
diff --git a/src/libraries/System.Security.Cryptography.Pkcs/tests/RecipientInfoCollectionTests.cs b/src/libraries/System.Security.Cryptography.Pkcs/tests/RecipientInfoCollectionTests.cs
index afac727cab4987..4bbeb912b61d66 100644
--- a/src/libraries/System.Security.Cryptography.Pkcs/tests/RecipientInfoCollectionTests.cs
+++ b/src/libraries/System.Security.Cryptography.Pkcs/tests/RecipientInfoCollectionTests.cs
@@ -142,7 +142,9 @@ public static void TestExplicitCopyToExceptions()
if (PlatformDetection.IsNonZeroLowerBoundArraySupported)
{
// Array has non-zero lower bound
+#pragma warning disable IL3050 // Creating multi-dimensional arrays is AOT safe, only SzArrays are problem
Array array = Array.CreateInstance(typeof(object), new int[] { 10 }, new int[] { 10 });
+#pragma warning restore IL3050
Assert.Throws(() => col.CopyTo(array, 0));
}
}
diff --git a/src/libraries/System.Security.Cryptography.Pkcs/tests/System.Security.Cryptography.Pkcs.Tests.csproj b/src/libraries/System.Security.Cryptography.Pkcs/tests/System.Security.Cryptography.Pkcs.Tests.csproj
index ac150e7c612e1d..ee52068c8a26ce 100644
--- a/src/libraries/System.Security.Cryptography.Pkcs/tests/System.Security.Cryptography.Pkcs.Tests.csproj
+++ b/src/libraries/System.Security.Cryptography.Pkcs/tests/System.Security.Cryptography.Pkcs.Tests.csproj
@@ -4,8 +4,6 @@
$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent);$(NetFrameworkCurrent)
$(NoWarn);SYSLIB0057
$(NoWarn);SYSLIB5006
-
- false
ContextGenerationSpec ctx2 = result2.ContextGenerationSpecs[i];
Assert.NotSame(ctx1, ctx2);
+#pragma warning disable IL2026 // https://github.com/dotnet/runtime/issues/126862
GeneratorTestHelpers.AssertStructurallyEqual(ctx1, ctx2);
+#pragma warning restore IL2026
Assert.Equal(ctx1, ctx2);
Assert.Equal(ctx1.GetHashCode(), ctx2.GetHashCode());
@@ -89,7 +91,9 @@ public partial class JsonContext : JsonSerializerContext { }
ContextGenerationSpec ctx2 = result2.ContextGenerationSpecs[0];
Assert.NotSame(ctx1, ctx2);
+#pragma warning disable IL2026 // https://github.com/dotnet/runtime/issues/126862
GeneratorTestHelpers.AssertStructurallyEqual(ctx1, ctx2);
+#pragma warning restore IL2026
Assert.Equal(ctx1, ctx2);
Assert.Equal(ctx1.GetHashCode(), ctx2.GetHashCode());
@@ -176,7 +180,9 @@ void Visit(object? node)
return;
}
+#pragma warning disable IL2075 // https://github.com/dotnet/runtime/issues/126862
foreach (FieldInfo field in type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
+#pragma warning restore IL2075
{
object? fieldValue = field.GetValue(node);
Visit(fieldValue);
diff --git a/src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Unit.Tests/System.Text.Json.SourceGeneration.Roslyn3.11.Unit.Tests.csproj b/src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Unit.Tests/System.Text.Json.SourceGeneration.Roslyn3.11.Unit.Tests.csproj
index 75483ada3234b3..5326f2b2da2d3d 100644
--- a/src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Unit.Tests/System.Text.Json.SourceGeneration.Roslyn3.11.Unit.Tests.csproj
+++ b/src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Unit.Tests/System.Text.Json.SourceGeneration.Roslyn3.11.Unit.Tests.csproj
@@ -4,8 +4,6 @@
true
false
-
- false
diff --git a/src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Unit.Tests/System.Text.Json.SourceGeneration.Roslyn4.4.Unit.Tests.csproj b/src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Unit.Tests/System.Text.Json.SourceGeneration.Roslyn4.4.Unit.Tests.csproj
index 89318aec9c5b5d..b453e5051e1693 100644
--- a/src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Unit.Tests/System.Text.Json.SourceGeneration.Roslyn4.4.Unit.Tests.csproj
+++ b/src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Unit.Tests/System.Text.Json.SourceGeneration.Roslyn4.4.Unit.Tests.csproj
@@ -3,8 +3,6 @@
$(MicrosoftCodeAnalysisVersion_4_8)
$(DefineConstants);ROSLYN4_0_OR_GREATER;ROSLYN4_4_OR_GREATER
true
-
- false
diff --git a/src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Unit.Tests/System.Text.Json.SourceGeneration.Unit.Tests.targets b/src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Unit.Tests/System.Text.Json.SourceGeneration.Unit.Tests.targets
index 50f7912bf9cbc8..1c425a78879baa 100644
--- a/src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Unit.Tests/System.Text.Json.SourceGeneration.Unit.Tests.targets
+++ b/src/libraries/System.Text.Json/tests/System.Text.Json.SourceGeneration.Unit.Tests/System.Text.Json.SourceGeneration.Unit.Tests.targets
@@ -31,6 +31,7 @@
+
diff --git a/src/libraries/System.Threading.RateLimiting/tests/Infrastructure/Utils.cs b/src/libraries/System.Threading.RateLimiting/tests/Infrastructure/Utils.cs
index c807c197f1ee0a..9e51dcc985e1c3 100644
--- a/src/libraries/System.Threading.RateLimiting/tests/Infrastructure/Utils.cs
+++ b/src/libraries/System.Threading.RateLimiting/tests/Infrastructure/Utils.cs
@@ -28,14 +28,12 @@ internal static PartitionedRateLimiter CreatePartitionedLimiterWithou
}
// Gets and runs the Heartbeat function on the DefaultPartitionedRateLimiter
- internal static Task RunTimerFunc(PartitionedRateLimiter limiter)
+ internal static Task RunTimerFunc(PartitionedRateLimiter limiter)
{
// Use Type.GetType so that trimming can see what type we're reflecting on, but assert it's the one we got
var limiterTypeDef = Type.GetType("System.Threading.RateLimiting.DefaultPartitionedRateLimiter`2, System.Threading.RateLimiting");
- var limiterType = limiter.GetType();
- Assert.Equal(limiterTypeDef, limiterType.GetGenericTypeDefinition());
- if (string.Empty.Length > 0)
- limiterType = limiterTypeDef;
+ var limiterType = limiterTypeDef.MakeGenericType(typeof(TResource), typeof(TKey));
+ Assert.Equal(limiter.GetType(), limiterType);
var innerTimer = limiterType.GetField("_timer", BindingFlags.NonPublic | BindingFlags.Instance);
Assert.NotNull(innerTimer);
diff --git a/src/libraries/System.Threading.RateLimiting/tests/PartitionedRateLimiterTests.cs b/src/libraries/System.Threading.RateLimiting/tests/PartitionedRateLimiterTests.cs
index 21e611bffc0812..ff6e7c4264941b 100644
--- a/src/libraries/System.Threading.RateLimiting/tests/PartitionedRateLimiterTests.cs
+++ b/src/libraries/System.Threading.RateLimiting/tests/PartitionedRateLimiterTests.cs
@@ -517,7 +517,7 @@ public async Task IdleLimiterIsCleanedUp()
};
innerLimiter.IdleDurationImpl = () => TimeSpan.FromMinutes(1);
- await Utils.RunTimerFunc(limiter);
+ await Utils.RunTimerFunc(limiter);
// Limiter is disposed when timer runs and sees that IdleDuration is greater than idle limit
await tcs.Task;
@@ -576,7 +576,7 @@ public async Task AllIdleLimitersCleanedUp_DisposeThrows()
innerLimiter2.IdleDurationImpl = () => TimeSpan.FromMinutes(1);
// Run Timer
- var ex = await Assert.ThrowsAsync(() => Utils.RunTimerFunc(limiter));
+ var ex = await Assert.ThrowsAsync(() => Utils.RunTimerFunc(limiter));
Assert.True(dispose1Called);
Assert.True(dispose2Called);
@@ -625,7 +625,7 @@ public async Task ThrowingTryReplenishDoesNotPreventIdleLimiterBeingCleanedUp()
};
idleLimiter.IdleDurationImpl = () => TimeSpan.FromMinutes(1);
- var ex = await Assert.ThrowsAsync(() => Utils.RunTimerFunc(limiter));
+ var ex = await Assert.ThrowsAsync(() => Utils.RunTimerFunc(limiter));
Assert.Single(ex.InnerExceptions);
// Wait for Timer to run again which will see the throwing TryReplenish and an idle limiter it needs to clean-up
@@ -649,7 +649,7 @@ public async Task ChainedLimiter_HeartbeatCallsTryReplenishOnInnerReplenishingLi
limiter.AttemptAcquire("");
- await Utils.RunTimerFunc(limiter);
+ await Utils.RunTimerFunc(limiter);
Assert.Equal(1, replenishCallCount);
}
@@ -675,7 +675,7 @@ public async Task ChainedLimiter_HeartbeatCallsTryReplenishOnAllInnerReplenishin
limiter.AttemptAcquire("");
- await Utils.RunTimerFunc(limiter);
+ await Utils.RunTimerFunc(limiter);
Assert.Equal(1, replenishCallCount1);
Assert.Equal(1, replenishCallCount2);
@@ -701,7 +701,7 @@ public async Task ChainedLimiter_ThrowingTryReplenishStillReplenishesOtherLimite
limiter.AttemptAcquire("");
- var ex = await Assert.ThrowsAsync(() => Utils.RunTimerFunc(limiter));
+ var ex = await Assert.ThrowsAsync(() => Utils.RunTimerFunc(limiter));
Assert.Single(ex.InnerExceptions);
Assert.IsType(ex.InnerExceptions[0]);
@@ -734,7 +734,7 @@ public async Task ChainedLimiter_IdleChainedLimiterWithNullChildIdleDurationNotE
idleLimiter.IdleDurationImpl = () => TimeSpan.FromMinutes(1);
replenishLimiter.IdleDurationImpl = () => null;
- await Utils.RunTimerFunc(limiter);
+ await Utils.RunTimerFunc(limiter);
// Factory should not have been called again — limiter was not evicted
limiter.AttemptAcquire("");
@@ -768,7 +768,7 @@ public async Task ChainedLimiter_FullyIdleChainedLimiterIsEvicted()
innerLimiter1.DisposeAsyncCoreImpl = () => default;
innerLimiter2.DisposeAsyncCoreImpl = () => default;
- await Utils.RunTimerFunc(limiter);
+ await Utils.RunTimerFunc(limiter);
// Factory should be called again on next acquire — limiter was evicted and recreated
limiter.AttemptAcquire("");
diff --git a/src/libraries/System.Threading.RateLimiting/tests/System.Threading.RateLimiting.Tests.csproj b/src/libraries/System.Threading.RateLimiting/tests/System.Threading.RateLimiting.Tests.csproj
index 0169f249b4a2e5..7ddffeb4910c59 100644
--- a/src/libraries/System.Threading.RateLimiting/tests/System.Threading.RateLimiting.Tests.csproj
+++ b/src/libraries/System.Threading.RateLimiting/tests/System.Threading.RateLimiting.Tests.csproj
@@ -2,8 +2,6 @@
$(NetCoreAppCurrent);$(NetFrameworkCurrent)
-
- false
@@ -20,7 +18,7 @@
-
+