3

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.

Purple Haze
  • 530
  • 7
  • 22
  • `Creating a process for each test is an overkill` compared to creating **entire AppDomains** for the purpose of running tests, no it's not. Just because it's more effort than calling `AppDomain.CreateDomain` doesn't make it overkill. – Ian Kemp Apr 30 '21 at 10:24
  • Aren't App domains created within processes ? – Purple Haze Apr 30 '21 at 10:34
  • **AppDomains are not a thing in .NET Core/5.0 and likely never will be**. Just forget that they exist. – Ian Kemp Apr 30 '21 at 10:39
  • 1
    That's what i am trying to ask, do you think the only approach is creating a process for each test ? – Purple Haze Apr 30 '21 at 10:40
  • 2
    Most test frameworks have the option of running individual tests/test classes in isolated processes. Perhaps include what test framework you are using so you can get the answer to your *real* question – pinkfloydx33 Apr 30 '21 at 11:11
  • I am using Ms Test – Purple Haze Apr 30 '21 at 11:21
  • Not sure what answer do you expect here. AppDomains are gone, you can't just "Replace" them, even with a +100 bounty (or +500 for that matter). – Simon Mourier May 06 '21 at 06:36
  • The answer i am expecting, is to know if for my use case there is an alternative solution, i might have formulated the question badly. – Purple Haze May 06 '21 at 10:57
  • 1
    If you want isolation, you must create a new OS process. There's nothing beyond that. – Simon Mourier May 09 '21 at 15:40

1 Answers1

0

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/

Rahul Shukla
  • 646
  • 6
  • 19