Reputation: 1062
I keep getting the error below, and have been unable to figure it out. I am wondering if anyone can assist.
Error: Failed to load type for module MyExternalAssembly.MyNamespace.MyModule.
If this error occurred when using MEF in a Silverlight application, please ensure that the CopyLocal property of the reference to the MefExtensions assembly is set to true in the main application/shell and false in all other assemblies.
Error was: Unable to retrieve the module type MyExternalAssembly.MyNamespace.MyModule, MyExternalAssembly.MyNamespace, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null from the loaded assemblies. You may need to specify a more fully-qualified type name..
Code:
Load Screen (loads modules, stores Assembly reference for various uses)
string[] dynamicLibraries = Directory.GetFiles(pluginDirectory, "*.dll", SearchOption.AllDirectories);
// Parse through the DLL's and look for types that implement "IModule".
foreach (string file in dynamicLibraries)
{
// Get the plugin assembly information.
Assembly plugin = Assembly.LoadFile(file);
// Get all types that are exported for plugins.
IEnumerable<Type> modules = plugin.GetTypes()
.Where(t => typeof(IModule).IsAssignableFrom(t));
if (modules.Count() > 0)
{
ApplicationState.Instance.Plugins.Add(plugin, modules);
}
}
Here is the ConfigureModuleCatelog Method
protected override void ConfigureModuleCatalog()
{
base.ConfigureModuleCatalog();
ModuleCatalog catalog = (ModuleCatalog)this.ModuleCatalog;
foreach (var assembly in ApplicationState.Instance.Plugins)
{
foreach (var type in assembly.Value)
{
this.ModuleCatalog.AddModule(new ModuleInfo
{
ModuleName = type.FullName,
ModuleType = type.AssemblyQualifiedName,
Ref = new Uri(assembly.Key.Location, UriKind.RelativeOrAbsolute).AbsoluteUri,
InitializationMode = InitializationMode.WhenAvailable
});
}
}
}
Basically, I need a way to maintain/use this "Plugin" dictionary and get Modularization to wprk properly. And ideas?
Thanks!
Upvotes: 2
Views: 1860
Reputation: 178650
I'm confused. You say Unity but then your code is using MEF types. And if you're using MEF, why on Earth are you manually finding IModule
implementations - you should be using MEF to do the dynamic resolution for you.
Upvotes: 1