Tuesday, June 15, 2010

Silverlight 4 & RIA -- 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."

This is usually happend when required assemblies are not "copied to local" folder so that they are not included in Client.XAP file of silverlight.

There are two issues with Visual Studio that make this happen.
1. If a assembly is used and referenced in projects other than the Silverlight project, for example, used in common/data assembly, than the referenced assembly will not be copied to silverlight bin file.

2. If you changed folder structure of your solution, for example you create sub folder for client and client, put each projects under those folders. In most cases, the reference will be refered to its own bin folder.

No comments: