使用MEF加载程序集在某些系统上失败,没有任何错误消息

时间:2014-08-11 07:33:03

标签: c# .net dependency-injection mef

使用MEF的c#应用程序有一个奇怪的问题。我使用以下代码从应用程序的子目录加载插件。

public class Loader {


    [ImportMany]
    private IEnumerable<Lazy<IPlugin, IMeta>> operations = null;

    public IEnumerable<Lazy<IPlugin, IMeta>> Plugins {
        get {
            return this.operations;
        }
    }

    public void Load(string path) {

        try {
            // An aggregate catalog that combines multiple catalogs
            var catalog = new AggregateCatalog();

            // Add all the parts found in all assemblies in
            // the same directory as the executing program
            catalog.Catalogs.Add(new DirectoryCatalog(path));

            // Create the CompositionContainer with the parts in the catalog.
            CompositionContainer container = new CompositionContainer(catalog);

            // Fill the imports of this object
            container.ComposeParts(this);

            log.Debug("Done loading: " + path);
        } catch (Exception error) {
            log.Fatal(error);
        }
    }
}

这在90%的测试系统中运行良好。但是在一个系统上,Loader不会加载插件。没有消息或例外。是否存在阻止MEF动态加载的设置?

0 个答案:

没有答案