From d296b89450ce216258a45b5bb296cfbc6dd6ff09 Mon Sep 17 00:00:00 2001 From: Brandon Ording Date: Thu, 16 Jul 2026 18:01:54 -0400 Subject: [PATCH 1/2] Use AssemblyLoadContext --- src/Particular.AnalyzerTesting/BaseCompilationTest.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Particular.AnalyzerTesting/BaseCompilationTest.cs b/src/Particular.AnalyzerTesting/BaseCompilationTest.cs index d712754..398e51e 100644 --- a/src/Particular.AnalyzerTesting/BaseCompilationTest.cs +++ b/src/Particular.AnalyzerTesting/BaseCompilationTest.cs @@ -1,8 +1,8 @@ namespace Particular.AnalyzerTesting; -using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.Loader; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.Diagnostics; @@ -22,8 +22,7 @@ private protected BaseCompilationTest(string? outputAssemblyName = null) { this.outputAssemblyName = outputAssemblyName ?? "TestAssembly"; - var assemblies = AppDomain.CurrentDomain.GetAssemblies(); - foreach (var assembly in assemblies) + foreach (var assembly in AssemblyLoadContext.Default.Assemblies) { if (!assembly.IsDynamic && !string.IsNullOrWhiteSpace(assembly.Location)) { From 43bd9cc8af891372d4fc29a58c538e73ffcaaf8d Mon Sep 17 00:00:00 2001 From: Brandon Ording Date: Thu, 16 Jul 2026 18:02:43 -0400 Subject: [PATCH 2/2] Add references to framework assemblies --- .../BaseCompilationTest.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/Particular.AnalyzerTesting/BaseCompilationTest.cs b/src/Particular.AnalyzerTesting/BaseCompilationTest.cs index 398e51e..0cd3e61 100644 --- a/src/Particular.AnalyzerTesting/BaseCompilationTest.cs +++ b/src/Particular.AnalyzerTesting/BaseCompilationTest.cs @@ -1,7 +1,10 @@ namespace Particular.AnalyzerTesting; using System.Collections.Generic; +using System.IO; using System.Linq; +using System.Reflection.PortableExecutable; +using System.Runtime.InteropServices; using System.Runtime.Loader; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; @@ -29,6 +32,17 @@ private protected BaseCompilationTest(string? outputAssemblyName = null) References.Add(MetadataReference.CreateFromFile(assembly.Location)); } } + + foreach (var assemblyPath in Directory.EnumerateFiles(RuntimeEnvironment.GetRuntimeDirectory(), "*.dll")) + { + using var stream = File.OpenRead(assemblyPath); + using var file = new PEReader(stream); + + if (file.HasMetadata) + { + References.Add(MetadataReference.CreateFromFile(assemblyPath)); + } + } } private protected TSelf Self => (TSelf)this;