拦截ChangeRejectedException

时间:2018-06-22 10:14:02

标签: c#

如果文件在文件夹中,我正在尝试加载dll。为此,我这样做:

FileSystemWatcher filesw = new FileSystemWatcher();
string pathDossier = @"C:\Users\gfauconnier\Documents\Visual Studio 
2013\Projects\PluginAppSolution\PluginApp\bin\Debug\Plugin";
    DirectoryCatalog directoryCatalog;

    public PluginLoader(string path)
    {
        directoryCatalog = new DirectoryCatalog(path);

        filesw.Path = pathDossier;
        filesw.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName;
        filesw.Filter = "*.*";
        filesw.EnableRaisingEvents = true;
        filesw.Changed += new FileSystemEventHandler(OnChanged);

        var catalog = new AggregateCatalog(directoryCatalog);

        _Container = new CompositionContainer(catalog);

        _Container.ComposeParts(this);
    }

    private void OnChanged(object sender, FileSystemEventArgs e)
    {
        try
        {
            directoryCatalog.Refresh();
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }

        MessageBox.Show("refresh ok");
    }

问题是我最终遇到了以下我不理解的错误:

组成保持不变。由于以下错误,更改被拒绝:合成产生单个合成错误。最初的原因在下面提供。有关更多信息,请查看CompositionException.Errors属性。

1)修改了组件“ MyApp.PluginLoader”上不可重组的导入“ MyApp.PluginLoader.Plugins(ContractName =“ PluginContract.IPlugin”)”。

我按如下方式加载插件:

PluginLoader loader = new PluginLoader("Plugin");
        _Plugins = new Dictionary<string, IPlugin>();
        IEnumerable<IPlugin> plugins = loader.Plugins;

预先感谢您的帮助!

0 个答案:

没有答案
相关问题