<data name="ArrayTypeMismatch_ConstrainedCopy" xml:space="preserve">
<value>Array.ConstrainedCopy will only work on array types that are provably compatible, without any form of boxing, unboxing, widening, or casting of each array element. Change the array types (i.e., copy a Derived[] to a Base[]), or use a mitigation strategy in the CER for Array.Copy's less powerful reliability contract, such as cloning the array or throwing away the potentially corrupt destination array.</value>
</data>
- <data name="AssemblyLoadContext_Constructor_CannotInstantiateWhileUnloading" xml:space="preserve">
- <value>Cannot instantiate AssemblyLoadContext while the current process is exiting.</value>
- </data>
<data name="AssemblyLoadContext_Unload_CannotUnloadIfNotCollectible" xml:space="preserve">
<value>Cannot unload non-collectible AssemblyLoadContext.</value>
</data>
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;
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));
}
{
lock (s_allContexts)
{
- s_isProcessExiting = true;
foreach (var alcAlive in s_allContexts)
{
if (alcAlive.Value.TryGetTarget(out AssemblyLoadContext alc))
alc.RaiseUnloadEvent();
}
}
- s_allContexts.Clear();
}
}