diff options
author | Jan Vorlicek <janvorli@microsoft.com> | 2019-04-02 00:12:04 +0300 |
---|---|---|
committer | Marek Safar <marek.safar@gmail.com> | 2019-04-04 12:09:04 +0300 |
commit | 2f0ae8e621a96a4f25da44f29a9c873d9acbcb88 (patch) | |
tree | 097f0056ba981d33ad399a2ed485a89eca0bc2e0 /netcore/System.Private.CoreLib/shared/System/Runtime/Loader/AssemblyLoadContext.cs | |
parent | 41316a74382c4f5ac52ff77a808bd93c962e1a38 (diff) |
Remove s_isProcessExiting and Clear of ALC list at exit
Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
Diffstat (limited to 'netcore/System.Private.CoreLib/shared/System/Runtime/Loader/AssemblyLoadContext.cs')
-rw-r--r-- | netcore/System.Private.CoreLib/shared/System/Runtime/Loader/AssemblyLoadContext.cs | 18 |
1 files changed, 5 insertions, 13 deletions
diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/Loader/AssemblyLoadContext.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Loader/AssemblyLoadContext.cs index 2c68a27c1a0..a2c8df0ba8a 100644 --- a/netcore/System.Private.CoreLib/shared/System/Runtime/Loader/AssemblyLoadContext.cs +++ b/netcore/System.Private.CoreLib/shared/System/Runtime/Loader/AssemblyLoadContext.cs @@ -30,7 +30,6 @@ namespace System.Runtime.Loader private static readonly Dictionary<long, WeakReference<AssemblyLoadContext>> s_allContexts = new Dictionary<long, WeakReference<AssemblyLoadContext>>(); private static long s_nextId; - private static bool s_isProcessExiting; // Indicates the state of this ALC (Alive or in Unloading state) private InternalState _state; @@ -74,19 +73,14 @@ namespace System.Runtime.Loader GC.SuppressFinalize(this); } + // If this is a collectible ALC, we are creating a weak handle tracking resurrection otherwise we use a strong handle + var thisHandle = GCHandle.Alloc(this, IsCollectible ? GCHandleType.WeakTrackResurrection : GCHandleType.Normal); + var thisHandlePtr = GCHandle.ToIntPtr(thisHandle); + _nativeAssemblyLoadContext = InitializeAssemblyLoadContext(thisHandlePtr, representsTPALoadContext, isCollectible); + // Add this instance to the list of alive ALC lock (s_allContexts) { - if (s_isProcessExiting) - { - throw new InvalidOperationException(SR.AssemblyLoadContext_Constructor_CannotInstantiateWhileUnloading); - } - - // If this is a collectible ALC, we are creating a weak handle tracking resurrection otherwise we use a strong handle - var thisHandle = GCHandle.Alloc(this, IsCollectible ? GCHandleType.WeakTrackResurrection : GCHandleType.Normal); - var thisHandlePtr = GCHandle.ToIntPtr(thisHandle); - _nativeAssemblyLoadContext = InitializeAssemblyLoadContext(thisHandlePtr, representsTPALoadContext, isCollectible); - _id = s_nextId++; s_allContexts.Add(_id, new WeakReference<AssemblyLoadContext>(this, true)); } @@ -385,7 +379,6 @@ namespace System.Runtime.Loader { lock (s_allContexts) { - s_isProcessExiting = true; foreach (var alcAlive in s_allContexts) { if (alcAlive.Value.TryGetTarget(out AssemblyLoadContext alc)) @@ -393,7 +386,6 @@ namespace System.Runtime.Loader alc.RaiseUnloadEvent(); } } - s_allContexts.Clear(); } } |