From d2b20b9423309cca893929729056beffab6e2f1b Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Mon, 27 Jul 2020 12:50:37 -0700 Subject: [PATCH 1/3] Fix releasing of file handle for assembly bind --- src/coreclr/src/binder/bindertracing.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/coreclr/src/binder/bindertracing.cpp b/src/coreclr/src/binder/bindertracing.cpp index 2e5c83d7b09bd2..be09ebced11edc 100644 --- a/src/coreclr/src/binder/bindertracing.cpp +++ b/src/coreclr/src/binder/bindertracing.cpp @@ -216,14 +216,14 @@ namespace BinderTracing AssemblyBindOperation::~AssemblyBindOperation() { - if (!BinderTracing::IsEnabled() || ShouldIgnoreBind()) - return; - - // Make sure the bind request is populated. Tracing may have been enabled mid-bind. - if (!m_populatedBindRequest) - PopulateBindRequest(m_bindRequest); + if (BinderTracing::IsEnabled() && !ShouldIgnoreBind()) + { + // Make sure the bind request is populated. Tracing may have been enabled mid-bind. + if (!m_populatedBindRequest) + PopulateBindRequest(m_bindRequest); - FireAssemblyLoadStop(m_bindRequest, m_resultAssembly, m_cached); + FireAssemblyLoadStop(m_bindRequest, m_resultAssembly, m_cached); + } if (m_resultAssembly != nullptr) m_resultAssembly->Release(); From 581d68dacee4e083d1e086c777431878fe72a419 Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Mon, 27 Jul 2020 13:50:47 -0700 Subject: [PATCH 2/3] Make test delete assembly file --- .../tests/CollectibleAssemblyLoadContextTest.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/libraries/System.Runtime.Loader/tests/CollectibleAssemblyLoadContextTest.cs b/src/libraries/System.Runtime.Loader/tests/CollectibleAssemblyLoadContextTest.cs index 90527c3d0be9de..b054b6bc5d261f 100644 --- a/src/libraries/System.Runtime.Loader/tests/CollectibleAssemblyLoadContextTest.cs +++ b/src/libraries/System.Runtime.Loader/tests/CollectibleAssemblyLoadContextTest.cs @@ -106,6 +106,20 @@ public void CheckContextUnloaded() class CollectibleWithOneAssemblyLoadedTest : TestBase { + string _assemblyPath; + + [MethodImpl(MethodImplOptions.NoInlining)] + public void Execute() + { + _assemblyPath = _testClassTypes[0].Assembly.Location; + } + + public void DeleteAssemblyFile() + { + // ResourceAssemblyLoadContext outputs each loaded assembly to TEMP, so we + // can delete an unloaded assembly file without affecting other loads + File.Delete(_assemblyPath); + } } [Fact] @@ -117,9 +131,11 @@ public static void Unload_CollectibleWithOneAssemblyLoaded() var test = new CollectibleWithOneAssemblyLoadedTest(); test.CreateContextAndLoadAssembly(); + test.Execute(); test.UnloadAndClearContext(); test.CheckContextUnloaded(); + test.DeleteAssemblyFile(); } class CollectibleWithOneAssemblyLoadedWithStaticTest : TestBase From d01d6da3f50565a466c56737250f69c2816ec2a9 Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Mon, 27 Jul 2020 15:43:42 -0700 Subject: [PATCH 3/3] Revert "Make test delete assembly file" This reverts commit 581d68dacee4e083d1e086c777431878fe72a419. --- .../tests/CollectibleAssemblyLoadContextTest.cs | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/src/libraries/System.Runtime.Loader/tests/CollectibleAssemblyLoadContextTest.cs b/src/libraries/System.Runtime.Loader/tests/CollectibleAssemblyLoadContextTest.cs index b054b6bc5d261f..90527c3d0be9de 100644 --- a/src/libraries/System.Runtime.Loader/tests/CollectibleAssemblyLoadContextTest.cs +++ b/src/libraries/System.Runtime.Loader/tests/CollectibleAssemblyLoadContextTest.cs @@ -106,20 +106,6 @@ public void CheckContextUnloaded() class CollectibleWithOneAssemblyLoadedTest : TestBase { - string _assemblyPath; - - [MethodImpl(MethodImplOptions.NoInlining)] - public void Execute() - { - _assemblyPath = _testClassTypes[0].Assembly.Location; - } - - public void DeleteAssemblyFile() - { - // ResourceAssemblyLoadContext outputs each loaded assembly to TEMP, so we - // can delete an unloaded assembly file without affecting other loads - File.Delete(_assemblyPath); - } } [Fact] @@ -131,11 +117,9 @@ public static void Unload_CollectibleWithOneAssemblyLoaded() var test = new CollectibleWithOneAssemblyLoadedTest(); test.CreateContextAndLoadAssembly(); - test.Execute(); test.UnloadAndClearContext(); test.CheckContextUnloaded(); - test.DeleteAssemblyFile(); } class CollectibleWithOneAssemblyLoadedWithStaticTest : TestBase