diff --git a/linker/Tests/Mono.Linker.Tests.Core/DefaultChecker.cs b/linker/Tests/Mono.Linker.Tests.Core/DefaultChecker.cs
index df649a6cf2c3..632244821983 100644
--- a/linker/Tests/Mono.Linker.Tests.Core/DefaultChecker.cs
+++ b/linker/Tests/Mono.Linker.Tests.Core/DefaultChecker.cs
@@ -35,13 +35,13 @@ public override void Check(LinkedTestCaseResult linkResult)
int expectedNumberOfAssertionsToMake = 0;
- using (var original = AssemblyDefinition.ReadAssembly(linkResult.InputAssemblyPath.ToString()))
+ using (var original = ReadAssembly(linkResult.InputAssemblyPath))
{
- expectedNumberOfAssertionsToMake += PerformOutputAssemblyChecks(original, linkResult.LinkedAssemblyPath.Parent);
+ expectedNumberOfAssertionsToMake += PerformOutputAssemblyChecks(original.Definition, linkResult.LinkedAssemblyPath.Parent);
- using (var linked = AssemblyDefinition.ReadAssembly(linkResult.LinkedAssemblyPath.ToString()))
+ using (var linked = ReadAssembly(linkResult.LinkedAssemblyPath))
{
- expectedNumberOfAssertionsToMake += CompareAssemblies(original, linked);
+ expectedNumberOfAssertionsToMake += CompareAssemblies(original.Definition, linked.Definition);
}
}
@@ -53,6 +53,15 @@ public override void Check(LinkedTestCaseResult linkResult)
Assert.AreEqual(_assertionCounter.AssertionsMade, expectedNumberOfAssertionsToMake, $"Expected to make {expectedNumberOfAssertionsToMake} assertions, but only made {_assertionCounter.AssertionsMade}. The test may be invalid or there may be a bug in the checking logic");
}
+ private static AssemblyContainer ReadAssembly(NPath assemblyPath)
+ {
+ var readerParams = new ReaderParameters();
+ var resolver = new AssemblyResolver();
+ readerParams.AssemblyResolver = resolver;
+ resolver.AddSearchDirectory(assemblyPath.Parent.ToString());
+ return new AssemblyContainer(AssemblyDefinition.ReadAssembly(assemblyPath.ToString(), readerParams), resolver);
+ }
+
private int PerformOutputAssemblyChecks (AssemblyDefinition original, NPath outputDirectory)
{
var assembliesToCheck = original.MainModule.Types.SelectMany(t => t.CustomAttributes).Where(attr => attr.IsAssemblyAssertion()).ToArray();
@@ -253,6 +262,24 @@ public override string ToString()
}
}
+ private class AssemblyContainer : IDisposable
+ {
+ public readonly AssemblyResolver Resolver;
+ public readonly AssemblyDefinition Definition;
+
+ public AssemblyContainer(AssemblyDefinition definition, AssemblyResolver resolver)
+ {
+ Definition = definition;
+ Resolver = resolver;
+ }
+
+ public void Dispose()
+ {
+ Resolver?.Dispose();
+ Definition?.Dispose();
+ }
+ }
+
private class AssertionCounter
{
public int AssertionsMade { get; private set; }
diff --git a/linker/Tests/Mono.Linker.Tests.Core/Mono.Linker.Tests.Core.csproj b/linker/Tests/Mono.Linker.Tests.Core/Mono.Linker.Tests.Core.csproj
index 9fe47039be39..6028d42d5451 100644
--- a/linker/Tests/Mono.Linker.Tests.Core/Mono.Linker.Tests.Core.csproj
+++ b/linker/Tests/Mono.Linker.Tests.Core/Mono.Linker.Tests.Core.csproj
@@ -68,6 +68,10 @@
{d68133bd-1e63-496e-9ede-4fbdbf77b486}
Mono.Cecil
+
+ {dd28e2b1-057b-4b4d-a04d-b2ebd9e76e46}
+ Mono.Linker
+
{2c26601f-3e2f-45b9-a02f-58ee9296e19e}
Mono.Linker.Tests.Cases.Expectations