Skip to content

Commit add60ed

Browse files
authored
Disable debugger support in trimming tests (#48399)
...to avoid false positive from debugger display types and simplify test for `X509Certificate`.
1 parent 7e3dcf7 commit add60ed

File tree

2 files changed

+4
-21
lines changed

2 files changed

+4
-21
lines changed

src/DefaultBuilder/test/Microsoft.AspNetCore.TrimmingTests/Microsoft.AspNetCore.TrimmingTests.proj

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
<ItemGroup>
44
<TestConsoleAppSourceFiles Include="SlimBuilderDoesNotDependOnX509Test.cs">
5-
<DisabledFeatureSwitches>System.Text.Json.JsonSerializer.IsReflectionEnabledByDefault</DisabledFeatureSwitches>
5+
<DisabledFeatureSwitches>System.Text.Json.JsonSerializer.IsReflectionEnabledByDefault;System.Diagnostics.Debugger.IsSupported</DisabledFeatureSwitches>
66
<AdditionalSourceFiles>X509Utilities.cs</AdditionalSourceFiles>
77
</TestConsoleAppSourceFiles>
88
<TestConsoleAppSourceFiles Include="UseHttpsDoesDependOnX509Test.cs">
9-
<DisabledFeatureSwitches>System.Text.Json.JsonSerializer.IsReflectionEnabledByDefault</DisabledFeatureSwitches>
9+
<DisabledFeatureSwitches>System.Text.Json.JsonSerializer.IsReflectionEnabledByDefault;System.Diagnostics.Debugger.IsSupported</DisabledFeatureSwitches>
1010
<AdditionalSourceFiles>X509Utilities.cs</AdditionalSourceFiles>
1111
</TestConsoleAppSourceFiles>
1212
</ItemGroup>

src/DefaultBuilder/test/Microsoft.AspNetCore.TrimmingTests/X509Utilities.cs

+2-19
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,13 @@
1111

1212
public static class X509Utilities
1313
{
14-
public static bool HasCertificateType
15-
{
16-
get
17-
{
18-
var certificateType = GetType("System.Security.Cryptography", "System.Security.Cryptography.X509Certificates.X509Certificate");
19-
20-
// We're checking for members, rather than just the presence of the type,
21-
// because Debugger Display types may reference it without actually
22-
// causing a meaningful binary size increase.
23-
return certificateType is not null && GetMembers(certificateType).Any();
24-
}
25-
}
14+
public static bool HasCertificateType =>
15+
GetType("System.Security.Cryptography", "System.Security.Cryptography.X509Certificates.X509Certificate") is not null;
2616

2717
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2057:UnrecognizedReflectionPattern",
2818
Justification = "Returning null when the type is unreferenced is desirable")]
2919
private static Type? GetType(string assemblyName, string typeName)
3020
{
3121
return Type.GetType($"{typeName}, {assemblyName}");
3222
}
33-
34-
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2070:UnrecognizedReflectionPattern",
35-
Justification = "Returning null when the type is unreferenced is desirable")]
36-
private static MemberInfo[] GetMembers(Type type)
37-
{
38-
return type.GetMembers(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly);
39-
}
4023
}

0 commit comments

Comments
 (0)