Search code examples
c#.net-4.0mefextensibility

MEF-based app works great on local machine, but doesn't import AddIns when run from a network share


I am converting a home-grown plugin architecture to .NET 4.0's MEF. The MEF-based application works wonderfully when it is run from my local machine. When I move the application to network share and then run the application, however, MEF no longer loads my plugins.

When I attach a debugging session to the process and inspect the DirectoryCatalog object I see there are no items in the Assemblies or Parts properties. The FullPath is the correct directory and the LoadFiles property includes all of the DLLs in the directory being searched.

At first I thought this was a CasPol issue until I tried to modify the CasPol and received a warning saying that CasPol is no longer enabled by default in .NET 4.0. It must be something else. I have Full permissions to the directory in question.

Here is the property which will contain the imported AddIns:

[ImportMany]
private IEnumerable<IRecipient> RecipientAddIns;

And here is the method that discovers and imports the AddIns:

private void LoadRecipientAddIns()
{
  using (var catalog = new AggregateCatalog())
  {
    // Look for IRecipient AddIns in the ./Recipients directory.
    catalog.Catalogs.Add(new DirectoryCatalog("Recipients"));

    // Look for IRecipient AddIns in subdirectories hanging off of ./Recipients.
    foreach (string currentDirPath in Directory.GetDirectories("Recipients"))
      catalog.Catalogs.Add(new DirectoryCatalog(currentDirPath));

    using (var compositionContainer = new CompositionContainer(catalog))
    {
      compositionContainer.ComposeParts();
      compositionContainer.SatisfyImportsOnce(this);

      // The discovered AddIns should now be in the RecipientAddIns property.
    }

    // Do stuff with the Recipient AddIns
    foreach (var recipient in this.RecipientAddIns)
    {
      ...
    }
  }

  // Clear the list of discovered Recipient AddIns
  this.RecipientAddIns = null;
}

Any ideas?

Thank you.


Solution

  • Try loading the assemblies yourself (ie with Assembly.Load or LoadFrom). I suspect you'll get an exception, which the DirectoryCatalog is probably swallowing. The exception should help you figure out what's wrong.