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 and add a DirectoryCatalog
for a folder containing 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
stating:
"Could not load type 'Startup.ViewModels.ViewModel' from assembly 'G4S.XTime.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'."
I can't see why MEF can't load this type. When I try 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 are having Initialize
called, and I think this error is close to the root cause of that.
If I reference the modules, and use AssemblyCatalog
to load them, there is no problem at all and all works as it should. What could moving the assembly out to be loaded at runtime change to stop things working?
BTW, Common
isn't a module itself , but just a dependency of several modules.
TypeLoadException
have anInnerException
? Anyway, you can try to use Fuslogvw.exe (Assembly Binding Log Viewer) to troubleshoot assembly load failures. – DrunkometerTypeLoadException
doesn't have an exception, and my assembly binding log shows zero errors. This error seems to be somehow related to trying to load the type with reflection, later in the app, after assembly binding. – AnosmiaStartup.ViewModels.ViewModel
derived fromG4S.XTime.Common.XTimeViewModel
? – SetoseXTimeViewModel
is derived fromDevExpress.Xpf.Mvvm.ViewModelBase
. It used to be just calledViewModel
but the same in all other aspects.Startup
is the solution name, andViewModels
a child namespace ofCommon
. Very strange how it gets that type name. – AnosmiaAssembly.LoadFrom
, though Mef is usingAssembly.Load
using an assembly name instead of physical file path. WillAssembly.Load
work? – MornUnable to retrieve the module type {0} from the loaded assemblies. You may need to specify a more fully-qualified type name
. Maybe your problem is similar to my problem and its aboutGet Module Type
when we try to load modules dynamically byAssembly.Load
... I solved my problem with an unusual way (by some simple changes in prism library!!!). If you want i can give you my Custom Prism v4 Dlls to test them in your project. – Palaver