简体   繁体   中英

How can I deal with this MEF related ReflectionTypeLoadException exception?

I have three projects, viz Shell.Core , Shell , and Services.Employees . Shell imports parts from Services.Employees , ie the latter project is external and not referenced in any of the solution projects. As well as Shell , `Shell.Core' is also a WPF application, not a class library. I started it as that project type for DevExpress to include all the correct references for me, as it defines certain shared UI components.

Services.Employees does reference Core , which defines certain base classes it uses. Now, when the startup application, Shell , it should load Core , and then it does MEF composition, loading Services.Employees parts from a DirectoryCatalog, but MEF sees the dependencies on Core and wants to load them from that catalogue, although the host application already references these Core dependencies.

As example, when I try composition, I get an error like:

Exception: 'TypeLoadException': Could not load type 'Shell.Core.MappedViewModel`1' from assembly 'XTime900.Shell.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.

What are my ways out of this? Should I also import Shell.Core.MappedViewModel , although it is already in a referenced project? Should I convert Core to a class library, so it will appear in the catalogue directory as a DLL and MEF will load it as a dependency of Services.Employees ? Is there any other way to get around this sticky little problem?

It looks like this happened. Shell.Core.MappedViewModel1, referenced by the plugins, loaded the ViewModel types. Then, the MEF plugins referenced this project, and during composition, couldn't find the right objects. When I factored View Models out into a separate project, referenced by both Shell.Core.MappedViewModel1, referenced by the plugins, loaded the ViewModel types. Then, the MEF plugins referenced this project, and during composition, couldn't find the right objects. When I factored View Models out into a separate project, referenced by both Core` and the MEF imports, all worked well again.

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