Reputation: 4289
Now that it is possible to have two CLRs running on the same box, how could they 'talk' to each other?
Let's say that the GUI is running under .NET 2.0 CLR and there is a script running on the .NET 4.0 CLR, for example, is there a way to modify the 2.0 based GUI from the 4.0 environment?
I have this exact issue when I use this technique to inject an .NET C# REPL environment into another .net process: Video: Injecting C# DLLs into Managed (C#) and Unmanaged (C++) processes
Note: I asked a similar question at Reddit and that version contains large number of references which will be useful if you are interested in the topic of Side-by-Side execution and CLR Hosting
Upvotes: 3
Views: 1697
Reputation: 564931
Typically, in-process hosting of two separate CLRs is only done in the COM world. When you're using COM for extensibility, etc, the appropriate runtime is loaded. In this scenario, the CLR objects can "talk" to each other through COM, since COM is all about interoperability.
Pure managed applications will always end up running in the 4.0 CLR - so a 4.0 application loading a 2.0 assembly will end up executing the 2.0 assembly in CLR 4.
For details, see the CLR Inside Out: In-Process Side by Side article, which describes this in detail.
As for your specific examples:
Let's say that the GUI is running under .NET 2.0 CLR and there is a script running on the .NET 4.0 CLR, for example, is there a way to modify the 2.0 based GUI from the 4.0 environment?
If you try to load the 4.0 assembly directly, it'll fail. You'd have to use COM interop to load this, in which case all communication happens via COM. A 4.0 GUI application can load a 2.0 "script" -but it's loaded in the 4.0 runtime.
Upvotes: 7
Reputation: 9762
Theres two main ways, one is loosely coupled or tightly coupled.
In a loosely coupled system you would some form of bindings (JSON, XML, SOAP) to pass data back and forth. The benefit of this system is that you can use other programs in the future you may not have thought of to interact with the apps.
The other ways tightly coupled you can use plugins, or play around with the windows message pump to send messages back and forth. Also have a peek at the Windows Communication Framework
Upvotes: 1