From 334ab8420b7dc9711ec9e94c385ed309f008b87e Mon Sep 17 00:00:00 2001 From: Jevan Saks Date: Wed, 7 Oct 2026 11:51:16 -0700 Subject: [PATCH 1/2] Release cached synthetic metadata before test cleanup Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .../MetadataCache.cs | 16 +++++ .../Microsoft.Windows.CsWin32.csproj | 2 + .../InteriorPointerTests.cs | 3 + .../MetadataCacheTests.cs | 67 +++++++++++++++++++ 4 files changed, 88 insertions(+) create mode 100644 test/Microsoft.Windows.CsWin32.Tests/MetadataCacheTests.cs diff --git a/src/Microsoft.Windows.CsWin32/MetadataCache.cs b/src/Microsoft.Windows.CsWin32/MetadataCache.cs index c4d59996..20ae8f3b 100644 --- a/src/Microsoft.Windows.CsWin32/MetadataCache.cs +++ b/src/Microsoft.Windows.CsWin32/MetadataCache.cs @@ -40,4 +40,20 @@ internal MetadataFile GetMetadataFile(string path) return metadataFile; } } + + /// + /// Removes a file from the cache and releases its resources once all readers have been returned. + /// + /// The path to the metadata file to remove. + internal void RemoveMetadataFile(string path) + { + lock (this.metadataFiles) + { + if (this.metadataFiles.TryGetValue(path, out MetadataFile? metadataFile)) + { + this.metadataFiles.Remove(path); + metadataFile.Dispose(); + } + } + } } diff --git a/src/Microsoft.Windows.CsWin32/Microsoft.Windows.CsWin32.csproj b/src/Microsoft.Windows.CsWin32/Microsoft.Windows.CsWin32.csproj index 590405fe..ededc2d7 100644 --- a/src/Microsoft.Windows.CsWin32/Microsoft.Windows.CsWin32.csproj +++ b/src/Microsoft.Windows.CsWin32/Microsoft.Windows.CsWin32.csproj @@ -4,6 +4,7 @@ true netstandard2.0 enable + $(RootNamespace)