How free blocked assemblies in MEF2 (System.Composition 1.0.31) in .NET Core

222 Views Asked by At

I wrote some codes :

public interface IPlugin
{
    string Name { get; set; }
}

ClassLibrary1.dll

public class Class1 : IPlugin
{
    public string Name { get; set; } = "Hamed Fathi";
}

and a Console :

public static void Main(string[] args)
{
    var dir = @"PLUGIN DIRECTORY PATH";

    //Load Assemblies
    var files = Directory.EnumerateFiles(dir, "*.dll", SearchOption.TopDirectoryOnly);
    var assemblies = new List<Assembly>();
    foreach (var file in files)
        assemblies.Add(AssemblyLoadContext.Default.LoadFromAssemblyPath(file));

    //MEF2
    var conventions = new ConventionBuilder();
    conventions
        .ForTypesDerivedFrom<IPlugin>()
        .Export<IPlugin>()
        .Shared();
    var configuration = new ContainerConfiguration()
        .WithAssemblies(assemblies, conventions);
    var container = configuration.CreateContainer();
    var plugins = container.GetExports<IPlugin>().ToList();

    Console.ReadKey();
}

I want to use FileSystemWatcher for watching any changes in plugin's folder so I should can change/delete/rename/create any dlls.

so I have 3 questions :

1. When I load assemblies based on above code I can not change/delete any dll in plugin's folder. In .NET Framework I could use AppDomain and ShadowFolder for creating separated context.

Is there anyway to manipulate dlls when loaded by MEF2 ?

enter image description here

2. Is there anyway for reloading/refreshing/refetching assemblies by MEF2 ?

3. Is there anyway that I find pair of assembly's path and GetExports() ? Which exported types exists in which assembly ('s path).

0

There are 0 best solutions below