Skip to content

Fix ILVerifier holding files open #89127

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
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
@@ -1,6 +1,7 @@
// 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;
Expand All @@ -14,7 +15,7 @@
#nullable enable
namespace Mono.Linker.Tests.TestCasesRunner
{
sealed class ILVerifier : ILVerify.IResolver
sealed class ILVerifier : ILVerify.IResolver, IDisposable
{
readonly Verifier _verifier;
readonly NPath _assemblyFolder;
Expand Down Expand Up @@ -82,6 +83,9 @@ PEReader LoadAssemblyFromPath (string assemblyName, NPath pathToAssembly)

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"))
Expand Down Expand Up @@ -124,6 +128,13 @@ public static string GetErrorMessage (VerificationResult result)
{
return $"IL Verification error:\n{result.Message}";
}

public void Dispose()
{
foreach(var reader in _assemblyCache.Values)
reader.Dispose ();
_assemblyCache.Clear ();
}
}
}
#nullable restore
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public ResultChecker (BaseAssemblyResolver originalsResolver, BaseAssemblyResolv

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));
}
Expand Down