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
Core` and the MEF imports, all worked well again.
How can I deal with this MEF related ReflectionTypeLoadException exception?
-
30-07-2022 - |
質問
I have three projects, v.i.z. Shell.Core
, Shell
, and Services.Employees
. Shell
imports parts from Services.Employees
, i.e. 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?
解決