Unloading a dll file in mef

前端 未结 2 1345
被撕碎了的回忆
被撕碎了的回忆 2020-12-20 16:58

I have some plugins as dll files. My application loads the dll and it runs fine. but when I try to delete the old plugin and replace it with a new plugin it doesn\'t allow t

相关标签:
2条回答
  • 2020-12-20 17:07

    i have found that by using appdomain we can do that. but i am not able to find a solution in which mef is used.

    Unfortunately, this is not supported by MEF. MEF was designed specifically for application extensibility, not as a general purpose plugin system which supports unloading and replacement of code at runtime.

    The only way to make this work would be to use MEF within a separate AppDomain, and unload the AppDomain as a whole. The CLR itself has no support for unloading a loaded assembly other than unloading the entire AppDomain in which the assembly is opened.

    0 讨论(0)
  • 2020-12-20 17:09

    If you try to insert on catalog one Assembly Object like this:

    Assembly assembly = Assembly.Load(System.IO.File.ReadAllBytes(Path.Combine(directoryPath, ItemPlugin)));
    aggregateCatalog.Catalogs.Add(new AssemblyCatalog(assembly));
    

    You can Delete/Change the file later...

    0 讨论(0)
提交回复
热议问题