How can MEF resolve dependencies of assemblies that don't live at the root of the application?

Sep 23, 2011 at 7:09 PM

I have written my application to be a class library that is launched by a win32 MFC application.  Each of my views is a separate assembly that is located with the base class library that is located in a sub-directory of the hosted MFC application.

 

My question is, how can I get MEF to resolve the dependencies of my exported classes using the assemblies from this sub-directory instead of the root directory?

 

This is what I want:

ParentFolder

   myapp.exe

    Sub-Folder

          myMvvmWindow.dll

          myMvvmSubWindow.dll

          Microsoft.Expression.Interactions.dll

 

This is what I have to have now:

ParentFolder

   myapp.exe

   Microsoft.Expression.Interactions.dll

   Sub-Folder

          myMvvmWindow.dll

          myMvvmSubWindow.dll

          

Sep 26, 2011 at 9:42 PM

Once an assembly is loaded via MEF, the remaining items are loaded through the normal probe path, so dependent DLLs need to be discovered in the normal fashion, which is the GAC and the Application directory.

In the case of Microsoft.Expression.Interactions.dll, I would simply leave it at the root if necessary.

One workaround that may not be suitable for you, would be to load the catalog into a separate AppDomain with a private path pointing to your subdirectory, which would then allow those assemblies to be discovered.