Running on Windows, does a .NET Core process support in process side by side execution of .NET 4 as described here: https://docs.microsoft.com/en-us/dotnet/framework/deployment/in-process-side-by-side-execution
Thanks
If you are seeking "side-by-side" as per the referenced docs:
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.
Then the answer is No.
.NET Core is an independent framework, not an upgrade of .NET Framework. So running both DLLs in one process side-by-side for the above reasons is not relevant.
Is there a way to host one .NET Framework DLL and one .NET Core DLL in the same process?
Yes.
I have seen two kinds of possible ways:
w3wp.exe
When using in-process hosting, it is possible to load both CLR and CoreCLR into w3wp.exe
, but how this works I don't know. It should be a low level / runtime level thing that is outside the world of managed code.
DLL reference
A .NET Core application can directly reference a .NET Framework library as long as the targeting .NET Framework version implements .NET Standard. e.g. NET45+.
However, the .NET Framework code can perform differently when they are in .NET Core shell than they are in .NET Framework shell.
Consider this code:
// In .NET Framework library
public class Class1
{
public void Test()
{
var domain = AppDomain.CreateDomain("mydomain");
Console.WriteLine(domain);
}
}
If you reference this type in a .NET Core app, you could see a warning but no compile time error:
static void Main(string[] args)
{
var class1 = new Class1();
class1.Test();
}
When you run the code, you will get an exception:
System.PlatformNotSupportedException: 'Secondary AppDomains are not supported on this platform.'
Conversely, when you run the code in a .NET Framework shell, you see normal output:
Name:mydomain
There are no context policies.
Why?
This is because AppDomain
is type forwarded to different runtime libraries.
If you print out the assembly where the type resides:
Console.WriteLine(typeof(AppDomain).Assembly);
You could see for .NET Core, the output is:
System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
whereas for .NET Framework, the output is:
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?
According to this docs, app domains and remoting are not supported by .NET Core, so you can't do cross-domain communication based on those technologies.
If you look at the implementation of MarshalByRefObject
in .NET Core, it only throws exceptions.
However, network based communications (such as gRPC) are still possible.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With