// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
#nullable enable
namespace Mono.Linker.Tests.TestCasesRunner
{
- sealed class ILVerifier : ILVerify.IResolver
+ sealed class ILVerifier : ILVerify.IResolver, IDisposable
{
readonly Verifier _verifier;
readonly NPath _assemblyFolder;
bool TryLoadAssemblyFromFolder (string assemblyName, NPath folder, [NotNullWhen (true)] out PEReader? peReader)
{
+ if (_assemblyCache.TryGetValue (assemblyName, out peReader))
+ return true;
+
Assembly? assembly = null;
string assemblyPath = Path.Join (folder.ToString (), assemblyName);
if (File.Exists (assemblyPath + ".dll"))
{
return $"IL Verification error:\n{result.Message}";
}
+
+ public void Dispose()
+ {
+ foreach(var reader in _assemblyCache.Values)
+ reader.Dispose ();
+ _assemblyCache.Clear ();
+ }
}
}
#nullable restore
static void VerifyIL (NPath pathToAssembly, AssemblyDefinition linked)
{
- var verifier = new ILVerifier (pathToAssembly);
+ using var verifier = new ILVerifier (pathToAssembly);
foreach (var result in verifier.Results)
Assert.Fail (ILVerifier.GetErrorMessage (result));
}