Importing dlls using MEF

May 13, 2010 at 2:41 PM

I am using MEF to import my dlls, the development environment I am using is VS 2008 where I created the main app & the dlls that are imported -

When I copy the dll's to a separete directory & then read them in from that directory - I get the following error:

"Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information." seems like it can't find all the dlls

but when I load them in from the actual directory in which they were created then it works fine C:\Users\Documents\Visual Studio 2008\Projects\MyApp\MyControl\bin\x86\Debug\MyControl.dll

So my question is how can I make it work that it loads the dlls properly no matter where they are?


Jun 19, 2010 at 6:08 AM
I think your issue doesn't have anything to do with MEF, but with your projects' build properties. You must have a file in your build directory that is needed, but not present in the folder you copied everything to. Typically, when you get an error with MEF it'll have something to do with a failed export or import, in which case you won't get a LoaderException, but a CompositionException. That said, if you need to make sure you can compose parts in multiple folders, you need to create a DirectoryCatalog for each one and add them to your AggregateCatalog before composing.