prism:ViewModelLocator.AutoWireViewModel="True" will not work for not referenced assemblies
Basically, when the ViewModelLocationProvider calls the _defaultViewTypeToViewModelTypeResolver
, the call to Type.GetType(string) returns null.
This might be related to how MEF loads assemblies in general. This seems to be a common probem with MEF and a Google search will return a lot of results with similar issues.Here is someone with the same problem:
Type.GetType returns null when using MEF
You could try adding the plugin location in the probing path of the application.
I personally never use MEF as a DI container, because it's not one. But that is a conversation for another day.
EDIT:Actually, I just thought of a better way to get around this. Simply override ConfigureViewModelLocator in your bootstrapper like this:
protected override void ConfigureViewModelLocator() { base.ConfigureViewModelLocator(); ViewModelLocationProvider.SetDefaultViewTypeToViewModelTypeResolver(viewType => { var viewName = viewType.FullName; viewName = viewName.Replace(".Views.", ".ViewModels."); var viewAssemblyName = viewType.GetTypeInfo().Assembly.FullName; var suffix = viewName.EndsWith("View") ? "Model" : "ViewModel"; var viewModelName = String.Format(CultureInfo.InvariantCulture, "{0}{1}", viewName, suffix); var assembly = viewType.GetTypeInfo().Assembly; var type = assembly.GetType(viewModelName, true); return type; }); }
This way we can ask the assembly for the type directly and not try to have the framework figure it out for us.