|
I ran into this problem earlier and haven't found a solution (or relevant info online). I need to load an assembly at runtime and register one of its implementation with an existing interface:
Assembly assembly = Assembly.LoadFrom("CMFramework.Content.InjectedDemo.dll");
var types = assembly.GetExportedTypes().Where(type => typeof(IDemoRegionViewModel).IsAssignableFrom(type));
foreach (Type type in types)
_unityContainer.RegisterType(typeof(IDemoShellViewModel), type);
When it tries to register the loaded implementation it throws this error:
The type CMFramework.Content.InjectedDemo.DemoRegionInjectedViewModel cannot be assigned to variables of type CMFramework.Infrastructure.IContent.Demo.IDemoShellViewModel.
Parameter name: from
What doesn't make sense is the retrieved implementations have been confirmed as being assignable to the IDemoRegionViewModel inteface, but Unity is still throwing the error.
I've cleaned my project, ensured that the assemblies are up to date, and ensured that there is a reference in the CMFramework.Content.InjectedDemo project to the project containing the IDemoShellViewModel interface.
|