Skip to content

Commit 18169e5

Browse files
committed
Add a test confirming that X509Certificate is trimmed
...when using `CreateSlimBuilder`.
1 parent c5a9c59 commit 18169e5

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

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

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<ItemGroup>
4+
<TestConsoleAppSourceFiles Include="SlimBuilderDoesNotDependOnX509Test.cs" />
45
<TestConsoleAppSourceFiles Include="UseStartupThrowsForStructContainersTest.cs" />
56
</ItemGroup>
67

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
using System.Diagnostics.CodeAnalysis;
3+
using System.Linq;
4+
using System.Reflection;
5+
using Microsoft.AspNetCore.Builder;
6+
7+
#nullable enable
8+
9+
var builder = WebApplication.CreateSlimBuilder(args);
10+
_ = builder.Build();
11+
12+
if (GetType("System.Security.Cryptography", "System.Security.Cryptography.X509Certificates.X509Certificate") is not null) {
13+
return 1;
14+
}
15+
16+
return 100; // Success
17+
18+
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode",
19+
Justification = "Returning null when the type is unreferenced is desirable")]
20+
static Type? GetType(string assemblyName, string typeName) {
21+
var assembly = AppDomain.CurrentDomain.GetAssemblies().SingleOrDefault(a => a.GetName().Name == assemblyName);
22+
return assembly?.GetType(typeName);
23+
}

0 commit comments

Comments
 (0)