在 Windows 上运行,在 .NET 4 的进程并行执行中是否支持 .NET Core 进程,如下所述:https://docs.microsoft.com/en-us/dotnet/framework/deployment/in-process-side-by-side-execution
谢谢
最佳答案
如果您根据引用的文档寻求“并排”:
Installing a new version of the .NET Framework has no effect on existing applications.
Applications run against the version of the .NET Framework that they were built with. They do not use the new version of the .NET Framework unless expressly directed to do so. However, it is easier for applications to transition to using a new version of the .NET Framework.
那么答案是否 .
.NET Core 是一个独立的框架,不是 .NET Framework 的升级。因此,由于上述原因,在一个进程中并排运行两个 DLL 是无关紧要的。
Is there a way to host one .NET Framework DLL and one .NET Core DLL in the same process?
是的。
我见过两种可能的方式:
w3wp.exe
使用时 in-process hosting , it is possible to load both CLR and CoreCLR into
w3wp.exe
,但我不知道这是如何工作的。它应该是托管代码世界之外的低级别/运行时级别的东西。DLL 引用
.NET Core 应用程序可以直接引用 .NET Framework 库,只要定位 .NET Framework version implements .NET Standard .例如NET45+。
但是,.NET Framework 代码在 .NET Core shell 中的表现可能与在 .NET Framework shell 中不同。
考虑这个代码:
// In .NET Framework library
public class Class1
{
public void Test()
{
var domain = AppDomain.CreateDomain("mydomain");
Console.WriteLine(domain);
}
}
如果您在 .NET Core 应用程序中引用此类型,您可能会看到 warning但没有编译时错误:static void Main(string[] args)
{
var class1 = new Class1();
class1.Test();
}
当你运行代码时,你会得到一个异常:System.PlatformNotSupportedException: 'Secondary AppDomains are not supported on this platform.'
相反,当您在 .NET Framework shell 中运行代码时,您会看到正常的输出:Name:mydomain
There are no context policies.
为什么? 这是因为
AppDomain
类型转发到不同的运行时库。如果打印出类型所在的程序集:
Console.WriteLine(typeof(AppDomain).Assembly);
你可以看到 .NET Core 的输出是:System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
而对于 .NET Framework,输出为:mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
what kind of communication can I have between the two?
can I send serialized objects for example? Something similar on how two AppDomains can communicate?
根据 this docs 、.NET Core 不支持应用程序域和远程处理,因此您无法基于这些技术进行跨域通信。
如果你看看
MarshalByRefObject
的实现在 .NET Core 中,它只抛出异常。但是,基于网络的通信(例如 gRPC )仍然是可能的。
关于c# - .NET Core + .NET 4 在进程中并行执行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60424940/