简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM