This project has moved and is read-only. For the latest updates, please go here.

DirectoryCatalog sees no Parts when "Start Without Debugging"

May 29, 2009 at 5:02 PM


I have a fairly simple Composition action running where I look into a directory and its subfolders to load Parts.  When I run this code in Debug it discovers the parts without issue however when I run without debugging it doesn't discover any Parts.  This whole process is run in a Console Application and I have verified that both configurations are "looking" in the same directory in fact they load the same file that offers a part with exports.  Thanks for any help.


May 29, 2009 at 5:42 PM

Few questions to help in debugging?

1) where I look into a directory and its subfolders to load Parts. How are you including subfolders? By the DirectoryCatalog will not do a recursive directory lookup.
2) How do you know it is loading the same directory in both cases? Are you doing a debug print of the path? Is it a relative path?
3) You may want to do some debug print statements on the number of parts found in the Catalog in both cases just to check that they are in fact different and there isn't something else going wrong.
4) You can try loading the assembly you expect the exports to be in directly in an AssemblyCatalog to see if that works or not.

May 29, 2009 at 5:43 PM

Ok I have also discovered that when I turn OFF the Visual Studio hosting process I have them same issue when debugging.  Any thoughts?

May 29, 2009 at 5:56 PM

Here is my Directory Loading code

string optionsFolder = "Options";
var catalog = new AggregateCatalog();

if (Directory.Exists(optionsFolder))
        catalog.Catalogs.Add(new DirectoryCatalog(optionsFolder));

        foreach (string currentDirPath in Directory.GetDirectories(optionsFolder))
         Console.WriteLine("Examining " + currentDirPath);
                catalog.Catalogs.Add(new DirectoryCatalog(currentDirPath));
                DirectoryCatalog cat = catalog.Catalogs.Last() as DirectoryCatalog;
                foreach (string loadedFile in cat.LoadedFiles)
                Console.WriteLine("Found Parts " + cat.Parts.Count());

FWIW I also used the AssemblyCatalog and got the same result.  Hosting Process on it loads the Part turn it off and nothing.

May 31, 2009 at 1:20 AM

Out of curiousity do you have VS2010 Beta1 installed? As well as using System.ComponentModel.Composition.dll from the codeplex site? I'm just wondering if there is a mis-match with the some of your assemblies referencing System.ComponentModel.Composition from the GAC and some referencing a local built one from the codeplex site.

Also I'm curious what you get if you run your application from outside VS.. do you get the same issue?

Jun 1, 2009 at 2:45 PM

No not using VS2010 and the System.ComponentModel.Composition is version 2009.4.6.0.  Running the app on its own results in the same issue.

Jun 2, 2009 at 3:10 AM

Sorry I'm running out of ideas. Have you tried specifying the full directory path instead of the relative path? Can you post the output from the code you posted earlier for both with and without VS hosting process enabled. Also add similar debugging output for the root optionsFolder catalog. I'm grasping at straws but perhaps that information may give me some insight into whats going wrong.

If you are interested in debugging you could also put a conditional breakpoint on AttributedModelDiscovery.CreatePartDefinitionIfDiscoverable for the type you expect to be a part and step through the code to see why it doesn't discover any exports (of course with out the VS hosting process on, or perhaps in both cases to see the difference).

Jun 2, 2009 at 10:03 PM

I just ran into a similar issue, if not exactly the same issue and the problem was that some of the assemblies that contained my parts were x86 while the MEF host was x64 so the DirectoryCatalog was loading the assembly but not finding the parts in the x86 targeted assemblies because it was the wrong platform.

Make sure that all the assemblies have the same target platform.

Also, it might be good to have MEF issue a debug diagnostic of some sort when this happens if possible.

Jun 2, 2009 at 10:18 PM

I figured it out!  The Assembly that contained the exported part has the same name as the host console app that has the imported part just with different extensions of course (.dll vs. .exe).  Change the name and bingo it discovered it.  That is why it "appeared" to work while running in the Host Process.exe.