Note that there are some explanatory texts on larger screens.

plurals
  1. POMEF Runtime Plugin Update Issue
    text
    copied!<p><h1>Issue</h1> My MEF code is not appropriately updating assemblies during runtime, from a folder associated to a DirectoryCatalog. The plugins load at run-time succesffully, but when i update the dll and call Refresh on the DirectoryCatalog, the assemblies are not getting updated.</p> <p><h1>Background</h1> I am building a dll that has an MEF container, and uses a DirectoryCatalog to find a local plugin folder. I call this dll currently from a simple WinForm, that is setup to with a seperate project to use ShadowCopy so i can overwrite the dlls in my plugin folder. Instead of using a FileWatcher to update this folder, I am exposing a public method that calls refresh on the DirectoryCatalog, so i can update the assemblies at will instead of automatically.</p> <h1>Code</h1> <p>base class instantiates the MEF catalogs and container, and saves them as class variables for referential access later</p> <pre><code> public class FieldProcessor { private CompositionContainer _container; private DirectoryCatalog dirCatalog; public FieldProcessor() { var catalog = new AggregateCatalog(); //Adds all the parts found in the same assembly as the TestPlugin class catalog.Catalogs.Add(new AssemblyCatalog(typeof(TestPlugin).Assembly)); dirCatalog = new DirectoryCatalog(AppDomain.CurrentDomain.BaseDirectory + "Plugin\\"); catalog.Catalogs.Add(dirCatalog); //Create the CompositionContainer with the parts in the catalog _container = new CompositionContainer(catalog); } public void refreshCatalog() { dirCatalog.Refresh(); } } ... </code></pre> <p>here's the plugin i'm trying to overwrite. My test of updating, is that the stings returned are output to a text box, I change the Strings the plugin is returning, rebuild, and copy it in to the plugin folder. But it does not update for the running app, until i close and restart the app.</p> <pre><code>[Export(typeof(IPlugin))] [ExportMetadata("PluginName", "TestPlugin2")] public class TestPlugin2 : IPlugin { public IEnumerable&lt;IField&gt; GetFields(ContextObject contextObject, params string[] parameters) { List&lt;IField&gt; retList = new List&lt;IField&gt;(); //Do Work Return Wrok Results retList.Add(new Field("plugin.TestPlugin2", "TestPluginReturnValue2")); return retList; } } </code></pre> <p><h1>Edit</h1> Import Statement</p> <pre><code> [ImportMany(AllowRecomposition=true)] IEnumerable&lt;Lazy&lt;IPlugin, IPluginData&gt;&gt; plugins; </code></pre> <p><h1>Research</h1> I have done fairly extensive research and everywhere in articles and code samples the answer appears to be, to add a DirectoryCatalog to a container and save a reference of that catalog, then call Refresh on that reference, after a new plugin has bee added, and it will update the assemblies...which i am doing, but it's not showing updated output, from the new plugin dll.</p> <p><h1>Request</h1> Has anyone seen this issue, or know what may be causing my problems with the assemblies not updating during runtime? Any additional information or insight would be appreciated.</p> <p><h1>Resolution</h1> Thanks to Panos and Stumpy for their links which led me to the solution my issue. For future knowledge seekers, my main issue was that the Refresh method does not update assemblies, when the new assembly has the exact same assembly name as the overwritten dll. For my POC i just tested rebuilding with a Date appended to the assembly name and everything else the same, and it worked like a charm. their links in the comments below, were very useful, and are recommended if you have the same issue.</p>
 

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