title: Custom assembly resolve while building MAF pipeline
body: <p>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.</p>
  
  <p>The sample below uses the separate process isolation:</p>
  
  <pre><code>AddInStore.Rebuild(path);
  ...
  var ap = new AddInProcess();
  ap.Start();
  var addin = token.Activate&lt;MyAddInBase&gt;(ap, AddInSecurityLevel.FullTrust);
  </code></pre>
  
  <p>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):</p>
  
  <pre><code>- My.MainApp                    -&gt; /.
  - My.AddIn.Hosting              -&gt; /.
  - My.AddIn.Shared               -&gt; /.
  - My.AddIn.Contract             -&gt; /contracts
  - My.PlugIn.HostSideAdapter     -&gt; /HostSideAdapters
  - My.PlugIn.PlugInSideAdapter   -&gt; /PlugInSideAdapter
  - My.PlugIn.AddIn               -&gt; /AddInViews
  - My.SamplePlugin               -&gt; /addins/SamplePlugin
  </code></pre>
  
  <p>And the references</p>
  
  <pre><code>My.MainApp                  &lt;- My.AddIn.Hosting     (copy local = true)
  
  My.AddIn.Hosting            &lt;- My.AddIn.Shared      (copy local = true)
                              &lt;- My.AddIn.Contract    (copy local = false)
  
  My.PlugIn.AddIn             &lt;- My.AddIn.Contract    (copy local = false)
  
  My.PlugIn.HostSideAdapter   &lt;- My.AddIn.Hosting     (copy local = false)
                              &lt;- My.AddIn.Contract    (copy local = false)
  
  My.PlugIn.PlugInSideAdapter &lt;- My.PlugIn.AddIn      (copy local = false)
                              &lt;- My.AddIn.Contract    (copy local = false)
  
  My.SamplePlugin             &lt;- My.PlugIn.AddIn      (copy local = false)
                              &lt;- My.AddIn.Contract    (copy local = false)
  </code></pre>
  
  <p>This gives me a clean build with single dlls in each pipeline directory, everything works fine, pipeline is build, valid and working.</p>
  
  <p>Untill I add the problematic one:</p>
  
  <pre><code>My.AddIn.Shared     &lt;- My.AddIn.Contract    (copy local = false)
  
  My.AddIn.Hosting    &lt;- My.AddIn.Shared      (copy local = false)
  
  My.PlugIn.AddIn     &lt;- My.AddIn.Shared      (copy local = false)
  </code></pre>
  
  <p>This introduces a problem, because My.PlugIn.AddIn project can not be included in pipeline because:</p>
  
  <ol>
  <li>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)</li>
  <li>Unable to cast transparent proxy to my IContract type - (when
  colyLocal=true and AddInViews contains more than 1 dll)</li>
  </ol>
  
  <p>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.</p>
  
  <p>So, in both situations the addin cannot be loaded.
  I wanted to solve the problem by my custom handlers for events</p>
  
  <pre><code>AppDomain.CurrentDomain.AssemblyResolve
  AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve
  </code></pre>
  
  <p>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</p>
  
  <p>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?</p>