简体   繁体   English

在.Net Core 中替换 AppDomain.CreateDomain

[英]Replace AppDomain.CreateDomain in .Net Core

I am trying to migrate to.Net 5, where app domains are not supported anymore.我正在尝试迁移到不再支持应用程序域的.Net 5。

I used Application Domains in.Net Framework to launch multiple WPF tests without them interacting with each other.我使用 Application Domains in.Net Framework 启动了多个 WPF 测试,但它们之间没有交互。

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

And use the the appDomain to execute the application.并使用 appDomain 来执行应用程序。 In.Net 5 this is no longer possible. In.Net 5 这不再可能。

I looked into AssemblyLoadContext , i could not find any way to achieve this kind of isolation.我查看了AssemblyLoadContext ,我找不到任何方法来实现这种隔离。

I am using MS test as a testing framework, I could not find a way to isolate each test to a single process.我使用 MS 测试作为测试框架,我找不到将每个测试隔离到单个进程的方法。

Migrate from AppDomain to AssemblyLoadContext Maybe you still using the AppDomain in an application.从 AppDomain 迁移到 AssemblyLoadContext 也许您仍在应用程序中使用 AppDomain。 Now, the following code shows how to replace AppDomain methods by the appropriate equivalent method of AssemblyLoadContext现在,以下代码显示如何用 AssemblyLoadContext 的适当等效方法替换 AppDomain 方法

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://docs.microsoft.com/en-us/dotnet/api/system.runtime.loader.assemblyloadcontext?view=netcore-3.0 https://docs.microsoft.com/en-us/dotnet/api/system.runtime.loader.assemblyloadcontext?view=netcore-3.0

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM