What can stop loading MEF or Prism of my type?

I have a class:

public abstract class XTimeViewModel : DevExpress.Xpf.Mvvm.ViewModelBase { public bool PropertiesChanged { get; set; } [NotifyPropertyChangedInvocator] protected virtual void _onPropertyChanged(/*[CallerMemberName]*/ string propertyName = null) { PropertiesChanged = true; RaisePropertyChanged(propertyName); } } 

It is contained in an assembly called Common . When I try to add DirectoryCatalog for the folder with Common and other assemblies and dependencies such as DevExpress.Xpf.Mvvm.v13.2 :

 var catalog = new DirectoryCatalog(unitPath, "*.dll"); AggregateCatalog.Catalogs.Add(catalog); 

I get a ReflectionTypeLoadException , with a TypeLoadException indicating:

"Failed to load type 'Startup.ViewModels.ViewModel' from assembly 'G4S.XTime.Common, Version = 1.0.0.0, Culture = neutral, PublicKeyToken = zero." "

I do not understand why MEF cannot load this type. When I try the sample code:

 var asm = Assembly.LoadFrom(@"C:\Development\XTime\Startup\Units\G4S.XTime.Common.dll"); var vm = asm.GetType("G4S.XTime.Common.XTimeViewModel"); 

Then vm contains the correct type, i.e. G4S.XTime.Common.XTimeViewModel .

Just a hunch, but none of my loaded modules have Initialize , and I think this error is close to the root cause of this.

If I refer to the modules and use AssemblyCatalog to load them, there is no problem, and everything works as it should. What could make the assembly load at runtime to stop it?

BTW, Common not the module itself, but simply the dependency of several modules.

+6
source share
1 answer

Most likely, your dll is not in the same place as your startup exe. They exist if they directly reference exe (by default, the dll link is copied to the output directory).

Since you mentioned the Initialize () methods that are not called, maybe you are using Prism? if so, go through each step of the bootloader to make sure that the directory is correct (i.e. all types that you think should be there are actually there).

You did not show that the ViewModel in question is also marked as [Export], so make sure it is there and place a breakpoint in your ctor to make sure that it is actually created after the directory is created. those. when you create the view that the virtual machine is connected to).

Try to give us a full trace of the exceptions to see what really happens ... sometimes the root is buried in these type load exceptions.

0
source

All Articles