MEF: Unable to load one or more of the requested types

I recently walked into an issue with a WPF MEF application. The issues was only occurring on my machine, and not a colleagues. On starting the WPF application thought Visual Studio 2010 the exception “Unable to load one or more of the requested types” would be thrown inside DefaultPrismServiceRegistrar.GetRequiredPrismPartsToRegister(AggregateCatalog aggregateCatalog):

        private static IEnumerable<ComposablePartDefinition> GetRequiredPrismPartsToRegister(AggregateCatalog aggregateCatalog)
        {
            List<ComposablePartDefinition> partsToRegister = new List<ComposablePartDefinition>();
            var catalogWithDefaults = GetDefaultComposablePartCatalog();
            foreach (var part in catalogWithDefaults.Parts)
            {
                foreach (var export in part.ExportDefinitions)
                {
                    bool exportAlreadyRegistered = false;
                    foreach (var registeredPart in aggregateCatalog.Parts)
                    {
                        foreach (var registeredExport in registeredPart.ExportDefinitions)
                        {
                            if (string.Compare(registeredExport.ContractName, export.ContractName, StringComparison.Ordinal) == 0)
                            {
                                exportAlreadyRegistered = true;
                                break;
                            }
                        }
                    }

                    if (exportAlreadyRegistered != false) continue;
                    if (!partsToRegister.Contains(part))
                    {
                        partsToRegister.Add(part);
                    }
                }
            }
            return partsToRegister;
        }

It transpires that one of the application modules had referenced WPFToolkit.VisualStudio.Design which I assume is only for the Visual Studio design surface. Solution, remove the assembly reference.

Advertisement

~ by mdavey on December 14, 2010.

2 Responses to “MEF: Unable to load one or more of the requested types”

  1. I’m sure it wasn’t your intention, but you have just educated me that MEF is something you can use in WPF. I thought it was a Silverlight framework.

  2. This is a handy tool for to find out what imports are not being matched http://msdn.microsoft.com/en-us/library/ff576068.aspx in an application.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.

Join 272 other followers