Custom assembly resolve while building MAF pipeline

430 Views Asked by At

I am working on system that needs to support different degree of isolation for plugins. I have chosen MAF, since it matches my needs, supports separate process isolation and AppDomain isolation out of the box.

The sample below uses the separate process isolation:

AddInStore.Rebuild(path);
...
var ap = new AddInProcess();
ap.Start();
var addin = token.Activate<MyAddInBase>(ap, AddInSecurityLevel.FullTrust);

However I have a problems with making MAF work with libs that are shared between host and the plugin. Lets assume, I have projects (with output dirs):

- My.MainApp                    -> /.
- My.AddIn.Hosting              -> /.
- My.AddIn.Shared               -> /.
- My.AddIn.Contract             -> /contracts
- My.PlugIn.HostSideAdapter     -> /HostSideAdapters
- My.PlugIn.PlugInSideAdapter   -> /PlugInSideAdapter
- My.PlugIn.AddIn               -> /AddInViews
- My.SamplePlugin               -> /addins/SamplePlugin

And the references

My.MainApp                  <- My.AddIn.Hosting     (copy local = true)

My.AddIn.Hosting            <- My.AddIn.Shared      (copy local = true)
                            <- My.AddIn.Contract    (copy local = false)

My.PlugIn.AddIn             <- My.AddIn.Contract    (copy local = false)

My.PlugIn.HostSideAdapter   <- My.AddIn.Hosting     (copy local = false)
                            <- My.AddIn.Contract    (copy local = false)

My.PlugIn.PlugInSideAdapter <- My.PlugIn.AddIn      (copy local = false)
                            <- My.AddIn.Contract    (copy local = false)

My.SamplePlugin             <- My.PlugIn.AddIn      (copy local = false)
                            <- My.AddIn.Contract    (copy local = false)

This gives me a clean build with single dlls in each pipeline directory, everything works fine, pipeline is build, valid and working.

Untill I add the problematic one:

My.AddIn.Shared     <- My.AddIn.Contract    (copy local = false)

My.AddIn.Hosting    <- My.AddIn.Shared      (copy local = false)

My.PlugIn.AddIn     <- My.AddIn.Shared      (copy local = false)

This introduces a problem, because My.PlugIn.AddIn project can not be included in pipeline because:

  1. There is a problem during load of My.PlugIn.AddIn - dependency My.AddIn.Shared cannot be found (if AddInViews contains single dll with addin base)
  2. Unable to cast transparent proxy to my IContract type - (when colyLocal=true and AddInViews contains more than 1 dll)

Also, it is worth to mention only single class in My.PlugIn.AddIn is decorated with AddInBaseAttribute and shared assembly does not have a single one.

So, in both situations the addin cannot be loaded. I wanted to solve the problem by my custom handlers for events

AppDomain.CurrentDomain.AssemblyResolve
AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve

before calling AddInStore.Rebuild but this affects only the domain that my host app is ruuning and does not affect the dommain "Add-In Model Discovery worker AD" that is created internally by System.AddIn.Hosting.AddInStore

Since this class is static there is no way to override creation of the domain. Also it does not provide any events that will allow me to access to the inner-domain resolve errors. Is there any way to inject my custom assembly resolution rules or force the inner appDomain to inherit resolve events from my main one?

0

There are 0 best solutions below