I'm am currently revising a plugin architecture so that it utilizes AppDomains. The main difference between my plugins and the many examples I have found online is that instead of the plugin running and sending its results back to the main application, my main application is the one sending information to the plugin.
As it currently stands, I create an instance of the loader in a separate AppDomain. It then does all your normal initialization such as loading the plugin assembly. As this point, I then use the proxy of the loader to call the methods that send the data from the main application to the new AppDomain.
My problem occurs when I am attempting to call a method which has an argument type that is not serializable, and which does not derive from MarshalByRefObject.
Since these types are from 3rd party code, and the plugins expect to receive them, I cannot seem to find a way do this. After finding this question ( How to solve "Must be MarshalByRefObject" in a good but multiple-inheritance amputated language like C#? ), I was thinking about creating some sort of wrapper. My drawback here is that I simply cant figure out a way to make one without modifying the 3rd party code.
Here is an example of my issue:
// Cant modify this class
class ThirdPartyClass
{
// The properties are also 3rd party and nonserializable. These are accessed by the plugins.
public AnotherClass Property1{ get; set; }
public AnotherClass Property2{ get; set; }
public ThirdPartyClass(){}
}
class Loader : MarshalByRefObject
{
private Plugin plugin;
public Loader()
{
Assembly pluginAssembly = Assembly.LoadFrom("Full/Assembly/Path");
plugin = pluginAssembly.CreateInstance("Full.Plugin.Name") as Plugin;
}
public void DoSomething(ThirdPartyClass o)
{
...
plugin.DoSomethingElse(o);
}
}
class PluginManager
{
void Main(ThirdPartyClass o)
{
AppDomain pluginAppDomain = AppDomain.CreateDomain("Plugin AppDomain");
Loader loader = pluginAppDomain.CreateInstanceFromAndUnwrap("Full/Loader/Path", "Full.Loader.Name") as Loader;
// This is where I would have a problem.
loader.DoSomething(o);
}
}
Any help would be greatly appreciated.