DirectoryCatalog scans the assemblies in a directory to determine what classes are imported/exported. Any assemblies without an import/export are not loaded.
This is an awesome feature, but how does it work? To investigate the custom attributes on types in an assembly, don’t you need to load the Assembly? Once it is loaded, it cannot be unloaded, so that can’t be how this works.
Is it doing some sort of AppDomain magic?
Try it out.
DirectoryCatalogsimply creates anAssemblyCatalogfor every .dll file in the given directory. BecauseAssemblyCatalogcallsAssemblyName.GetAssemblyName, non-.NET .dll files will not be loaded (an exception is thrown and caught withinAssemblyCatalog).AssemblyCatalogcallsAssembly.Loadon theAssemblyNameit created. Thus, assemblies are immediately loaded when creating aDirectoryCatalog. No magic, noAppDomains. But thenMEFis well known to load assemblies into the currentAppDomain. Use MAF if you want assemblies that can be unloaded.