Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>when you load an assembly into the AppDomain in that way, it is the <em>current</em> AppDomain's PrivateBinPath that is used to find the assembly.</p> <p>For your example, when I added the following to my App.config it ran fine:</p> <pre><code>&lt;runtime&gt; &lt;assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"&gt; &lt;probing privatePath="[PATH_TO_PLUGIN]"/&gt; &lt;/assemblyBinding&gt; &lt;/runtime&gt; </code></pre> <p>This is not very useful to you though.</p> <p>What I did instead was to create a new assembly that contained the IPostPlugin and IPluginsHost interfaces, and also a class called Loader that looked like this:</p> <pre><code>public class Loader : MarshalByRefObject { public IPostPlugin[] LoadPlugins(string assemblyName) { var assemb = Assembly.Load(assemblyName); var types = from type in assemb.GetTypes() where typeof(IPostPlugin).IsAssignableFrom(type) select type; var instances = types.Select( v =&gt; (IPostPlugin)Activator.CreateInstance(v)).ToArray(); return instances; } } </code></pre> <p>I keep that new assembly in the application root, and it doesn't need to exist in the plugin directories (it can but won't be used as the application root will be searched first). </p> <p>Then in the main AppDomain I did this instead:</p> <pre><code>sandbox.Load(typeof(Loader).Assembly.FullName); Loader loader = (Loader)Activator.CreateInstance( sandbox, typeof(Loader).Assembly.FullName, typeof(Loader).FullName, false, BindingFlags.Public | BindingFlags.Instance, null, null, null, null).Unwrap(); var plugins = loader.LoadPlugins(AssemblyName.GetAssemblyName(f.FullName).FullName); foreach (var p in plugins) { p.Init(this); } _PostPlugins.AddRange(plugins); </code></pre> <p>So I create an instance of the known Loader type, and then get that to create the plugin instances from <em>within</em> the plug-in AppDomain. That way the PrivateBinPaths are used as you want them to be.</p> <p>One other thing, the private bin paths can be relative so rather than adding <code>d.FullName</code> you could add <code>pluginsDir + Path.DirectorySeparatorChar + d.Name</code> to keep the final path list short. That's just my personal preference though! Hope this helps.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload