Replace AppDomain.CreateDomain in .Net Core

3.4k views Asked by At

I am trying to migrate to .Net 5, where app domains are not supported anymore.

I used Application Domains in .Net Framework to launch multiple WPF tests without them interacting with each other.

 var appDomain = AppDomain.CreateDomain("Friendly name");

And use the the appDomain to execute the application. In .Net 5 this is no longer possible.

I looked into AssemblyLoadContext , i could not find any way to achieve this kind of isolation.

I am using MS test as a testing framework, I could not find a way to isolate each test to a single process.

1

There are 1 answers

0
Rahul Shukla On

Migrate from AppDomain to AssemblyLoadContext Maybe you still using the AppDomain in an application. Now, the following code shows how to replace AppDomain methods by the appropriate equivalent method of AssemblyLoadContext

Follow the below reference for the implementation and more details :

  // Create new "context" for loading assemblies:  

  var appDomain = AppDomain.CreateDomain("MyAppDomain");
  var assemblyLoadContext = new MyAssemblyLoadContext(name: "MyAssemblyLoadContext", isCollectible: true);

https://learn.microsoft.com/en-us/dotnet/api/system.runtime.loader.assemblyloadcontext?view=netcore-3.0

https://codetherapist.com/blog/netcore3-plugin-system/