Skip to content

Disable debugger support in trimming tests #48399

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

Merged
merged 1 commit into from
May 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

<ItemGroup>
<TestConsoleAppSourceFiles Include="SlimBuilderDoesNotDependOnX509Test.cs">
<DisabledFeatureSwitches>System.Text.Json.JsonSerializer.IsReflectionEnabledByDefault</DisabledFeatureSwitches>
<DisabledFeatureSwitches>System.Text.Json.JsonSerializer.IsReflectionEnabledByDefault;System.Diagnostics.Debugger.IsSupported</DisabledFeatureSwitches>
<AdditionalSourceFiles>X509Utilities.cs</AdditionalSourceFiles>
</TestConsoleAppSourceFiles>
<TestConsoleAppSourceFiles Include="UseHttpsDoesDependOnX509Test.cs">
<DisabledFeatureSwitches>System.Text.Json.JsonSerializer.IsReflectionEnabledByDefault</DisabledFeatureSwitches>
<DisabledFeatureSwitches>System.Text.Json.JsonSerializer.IsReflectionEnabledByDefault;System.Diagnostics.Debugger.IsSupported</DisabledFeatureSwitches>
<AdditionalSourceFiles>X509Utilities.cs</AdditionalSourceFiles>
</TestConsoleAppSourceFiles>
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,13 @@

public static class X509Utilities
{
public static bool HasCertificateType
{
get
{
var certificateType = GetType("System.Security.Cryptography", "System.Security.Cryptography.X509Certificates.X509Certificate");

// We're checking for members, rather than just the presence of the type,
// because Debugger Display types may reference it without actually
// causing a meaningful binary size increase.
return certificateType is not null && GetMembers(certificateType).Any();
}
}
public static bool HasCertificateType =>
GetType("System.Security.Cryptography", "System.Security.Cryptography.X509Certificates.X509Certificate") is not null;

[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2057:UnrecognizedReflectionPattern",
Justification = "Returning null when the type is unreferenced is desirable")]
private static Type? GetType(string assemblyName, string typeName)
{
return Type.GetType($"{typeName}, {assemblyName}");
}

[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2070:UnrecognizedReflectionPattern",
Justification = "Returning null when the type is unreferenced is desirable")]
private static MemberInfo[] GetMembers(Type type)
{
return type.GetMembers(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly);
}
}