public TestBase(int numContexts) { _contexts = new ResourceAssemblyLoadContext[numContexts]; _testClassTypes = new Type[numContexts]; _checker = new CollectibleChecker(numContexts); }
private static WeakReference <AssemblyLoadContext> CreateCollectible(CollectibleChecker checker) { var expectedContext = new ResourceAssemblyLoadContext(true); checker.SetAssemblyLoadContext(0, expectedContext); return(new WeakReference <AssemblyLoadContext>(expectedContext)); }
public static void Unload_CollectibleWithNoAssemblyLoaded() { // Use a collectible ALC + Unload // Check that we receive the Unloading event var checker = new CollectibleChecker(1); CreateAndLoadContext(checker); checker.GcAndCheck(); }
static void CreateAndLoadContext(CollectibleChecker checker) { var alc = new ResourceAssemblyLoadContext(true); checker.SetAssemblyLoadContext(0, alc); alc.Unload(); // Check that any attempt to load an assembly after an explicit Unload will fail Assert.Throws <InvalidOperationException>(() => alc.LoadFromAssemblyPath(Path.GetFullPath("none.dll"))); }
public static void Finalizer_CollectibleWithNoAssemblyLoaded() { // Use a collectible ALC, let the finalizer call Unload // Check that we receive the Unloading event var checker = new CollectibleChecker(1); // Create the ALC in another method to allow the finalizer to run WeakReference <AssemblyLoadContext> weakRef = CreateCollectible(checker); checker.GcAndCheck(); // Check that the ALC was also released AssemblyLoadContext alc; Assert.False(weakRef.TryGetTarget(out alc)); }