Derik Whittaker



MEF and decrypting LoaderExceptions

Have you ever received the following exception while using MEF?

Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.

if you have received this error did you scratch your head and wonder ‘what the F does this mean’?  Well the long and short of it is this.  This means that while trying to load an Export there was a dependency which could not be found during reflection.

The quick way to determine the cause of the error is to do as the image below shows:


What I would suggest is to wrap your MEF logic inside of a try-catch and explicitly catch ReflectionTypeLoadException.  Inside of your catch add some logic as such (just a PoC, copy-paster beware).

catch (ReflectionTypeLoadException tLException)
    var loaderMessages = new StringBuilder();
    loaderMessages.AppendLine("While trying to load composable parts the follwing loader exceptions were found: ");
    foreach (var loaderException in tLException.LoaderExceptions)

    // this is one of our custom exception types.
    throw new PluginLoadingException(loaderMessages.ToString(), tLException);

As you can see when you look at the LoaderExcpetions collections from my image above I had forgotten to reference AutoMapper in my plug-in and all hell broke lose (btw, no idea how this even compiled, but that is a different post).

Hope this helps.

Till next time,

Posted 01-31-2010 8:51 AM by Derik Whittaker
Filed under: ,



Joris wrote re: MEF and decrypting LoaderExceptions
on 03-03-2010 10:43 AM

You saved my day, thanks!

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Google Reader or Homepage Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of
Red-Gate Tools For SQL and .NET


SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
NHibernate Profiler
Balsamiq Mockups
JetBrains - ReSharper
Web Sequence Diagrams
Ducksboard<-- NEW Friend!


Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers


Community Server (Commercial Edition)