Search code examples
c#mefmvvm-light

MEF ReflectionTypeLoadException since migrating to MVVMLight


I have an application which is using MEF to get classes from libraries. I defined the Interface ISapphirePlugin, two libraries have classes which implement this Interface, and they should be loaded at application startup. Before I migrated to MVVM Light everything was working fine, but since the MVVM Light libraries are also in my application directoy, my MEF code fails. All libraries are in the same folder as my executable.

var catalog = new DirectoryCatalog(".");
var container = new CompositionContainer(catalog);
IEnumerable<ISapphirePlugin> modules = container.GetExportedValues<ISapphirePlugin>();

throws a ReflectionTypeLoadException, the loader exception says:

Could not load file or assembly 'Microsoft.Practices.ServiceLocation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.":"Microsoft.Practices.ServiceLocation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"}

Is there anything I can do?


Solution

  • I think MVVMLight requires the CommonServiceLocation nuget package now. This might help: Where does Microsoft.Practices.ServiceLocation come from?