有没有一种安全的方式可以使用DirectoryCatalog来处理目录不存在的情况?
以下是设置容器的代码示例:
以下是设置容器的代码示例:
//Create an assembly catalog of the assemblies with exports
var catalog = new AggregateCatalog(
new AssemblyCatalog(Assembly.GetExecutingAssembly()),
new AssemblyCatalog(Assembly.Load("My.Second.Assembly")),
new DirectoryCatalog("Plugins", "*.dll"));
//Create a composition container
var container = new CompositionContainer(catalog);
但是如果目录不存在,会抛出异常,我希望忽略这个错误。