Purple Haze
Purple Haze

Reputation: 550

Replace AppDomain.CreateDomain in .Net Core

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.

Upvotes: 4

Views: 4414

Answers (1)

Rahul Shukla
Rahul Shukla

Reputation: 716

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/

Upvotes: 1

Related Questions