MEF: “Unable to load one or more of the requested types. Retrieve the LoaderExceptions for more information”

前端 未结 3 647
抹茶落季
抹茶落季 2020-12-25 15:03

Scenario: I am using Managed Extensibility Framework to load plugins (exports) at runtime based on an interface contract defined in a separate dll. In my Visual Studio solut

3条回答
  •  滥情空心
    2020-12-25 15:52

    I have also run into a similar problem.

    If you are sure that you want to ignore such "bad" assemblies, then the solution is to call AssemblyCatalog.Parts.ToArray() right after creating each assembly catalog. This will trigger the ReflectionTypeLoadException which you mention. You then have a chance to catch the exception and ignore the bad assembly.

    When you have created AssemblyCatalog objects for all the "good" assemblies, you can aggregate them in an AggregateCatalog and pass that to the CompositionContainer constructor.

提交回复
热议问题