Communication between AppDomains
Asked Answered
G

1

4

We are building an app (WinForms, .NET 3.5) that loads "Plugin" DLLs into a secondary AppDomain. The secondary AppDomain needs to communicate occasionally with the 1st one (more specifically, call or get data from objects that are created in the main AppDomain).

I have read most of the material about AppDomains and communication between them.

So far, the only easy solution i've seen was inheriting from MarshalByRefObject and passing a TransparentProxy into the 2nd AppDomain, calling methods on the Proxy.

This method has its drawbacks (not always possible to inherit from MBRO in case of framework types for example, or types that already inherit from another class, static fields/classes and so on).

Since the current communication points are pretty constant (only 2-3 scenarios that require communication), i have considered creating a simple Mediator class with the following properties:

  1. Will be created in the 1st (Main) AppDomain.
  2. Would function only as a "message-passer" to the "Real" objects that are created in the main AppDomain.
  3. Will inherit from MBRO, and a proxy reference to it will be sent to the 2nd AppDomain.

Methods on this proxy object would be called, which in turn will call the methods on the "real" objects in the 1st AppDomain.

My questions --

  1. Does this seem like a logical design?
  2. More importantly, does a mediator/message passer class already exist in WCF or any other communcation framework? it seems like a generic concept and i am wondering if there is something similar.
Gregoriagregorian answered 23/1, 2012 at 13:26 Comment(4)
By reading the point Plugin i'm always asking first: "Did you ever heard about MEF?"Cabalist
Yes i have heard of it. AFAIK it is built into .NET, not sure about support for earlier versions... Also, i am not sure how it fits this specific scenario.Gregoriagregorian
I realize that it's been 18 months since the original post. I'm wondering how you made out. We're faced with similar constraints which MEF by itself can't address and that MAF seems to have gone the way of the dodo bird.Gwenngwenneth
What we did was to setup a WCF service that would act as this mediator PER subsystem that required communication from the 2nd appdomain (we only had 2 of those). Also, we made sure the interface that this mediator supported is very simple (methods that accept/return primitive types such as strings, etc). The "plugin" appdomain would create a WCF proxy to that object (using named pipes). This way, we were able to communicate between both appdomains.Gregoriagregorian
J
5

Unless you specifically want to avoid WCF for some reason, I would suggest taking a look at it. Specifically, you can use the NetNamedPipeBinding, which provides for communication on the same machine using named pipes. You can find some more information here: http://msdn.microsoft.com/en-us/library/system.servicemodel.netnamedpipebinding.aspx

As well, here is a reasonably concise blog entry demonstrating it's use (from a WMP plug-in to a third-party app).

Based on your description of the application, you could establish a WCF service in the first AppDomain then call into that service from the second AppDomain.

Jagir answered 23/1, 2012 at 13:42 Comment(5)
Thanks i will check it out. One question -- why do people promote the use of named pipes of different transport mediums? what are its advantages?Gregoriagregorian
In the context of WCF, the communication over named pipes is the mechanism most geared toward communication on an individual machine. In fact, you can't communicate over an endpoint with a NetNamedPipeBinding from another machine. The alternative bindings that are available out-of-the-box are generally heavier in terms of protocols (so NetNamedPipedBinding will probably be more performant), and once you start using them you need to start being more concerned about security (for example, locking down ports if you're using NetTcpBinding).Jagir
The link to codesnippet-managed-wmp-plugin-wcf-ipc is broken, do you know of another?Rebeckarebeka
@FrankSchwieterman Is this the link you were looking for? vikingco.de/codesnippet-managed-windows-media-plugins.htmlGwenngwenneth
@FrankSchwieterman this is the correct link: vikingco.de/codesnippet-managed-wmp-plugin-wcf-ipc.htmlCallboy

© 2022 - 2024 — McMap. All rights reserved.