load Prism modules from dll files (at startup)

Topics: Prism v4 - WPF 4
Apr 2, 2012 at 9:06 AM
Edited Apr 3, 2012 at 12:44 PM

At the moment in my application I do like this:

class Bootstrapper : UnityBootstrapper
   
{
       
protected override DependencyObject CreateShell()
       
{
           
return Container.Resolve<Shell>();
       
}

       
protected override void InitializeShell()
       
{
           
base.InitializeShell();

           
App.Current.MainWindow = (Window)Shell;
           
App.Current.MainWindow.Show();
       
}    

       
protected override void ConfigureModuleCatalog()
       
{            
           
base.ConfigureModuleCatalog();
           
var moduleCatalog = (ModuleCatalog)ModuleCatalog;

            moduleCatalog
.AddModule(typeof(FooModule));
            moduleCatalog
.AddModule(typeof(BarModule));
       
}        
   
}

I would like to load FooModule and BarModule by indicating the path to the dll file, something like this:

protected override void ConfigureModuleCatalog()
{
...
           
var assembly = Assembly.LoadFrom(@"libs\FooLib.dll");
           
var type = assembly.GetType("FooLib.FooModule");
            moduleCatalog
.AddModule(type);
...
}

but it doesn't work, I get this error message on Bootstrapper.Run() :

There is currently no moduleTypeLoader in the ModuleManager that can retrieve the specified module.

 

here's a stackoverflow question about this: http://stackoverflow.com/questions/9973546/load-prism-modules-from-dll-files-at-startup/9973664#comment12748865_9973664

please answer something, at least tell it's not possible to do or something  

Developer
Apr 3, 2012 at 5:05 PM

Hi,

Based on my understanding to achieve this kind of scenarios you could benefit from the functionalities already provided with Prism to discover new modules, like the Discovering Modules in a Directory approach or Registering Modules Using a Configuration File.

You could find more information about these and other possible approaches in the Prism documentation at MSDN:

On the other hand, I believe you could also try Registering Modules in Code, by defining the REF attribute, for example like in the following code snippet:

protected override void ConfigureModuleCatalog()
        {
            base.ConfigureModuleCatalog();

(...)
   
      moduleCatalog.AddModule(
      new ModuleInfo()
      {
          ModuleName = "ModuleName",
          ModuleType = "ModuleProject.ModuleClass, ModuleProject",
          Ref = "file://Modules/ModuleProject.dll"
      });

(...)

}

I hope you find this useful,

Agustin Adami
http://blogs.southworks.net/aadami


Apr 4, 2012 at 8:40 AM

thnx, the solution with Ref worked,

also "Discovering Modules in a Directory" worked, 

except for on Module called LogModule, if i copy it's binaries into the Module Catalog, when starting app I get this error:

Could not load file or assembly 'Microsoft.Windows.Design.Extensibility, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

 

even tough the Module doesn't references this library, and if I reference it, it will tell me that it doesn't has a subnamespace

here you can see all the referenced libraries: http://tinypic.com/r/a40c3o/5

Developer
Apr 4, 2012 at 6:56 PM

Hi,

I believe this error could be related to the fact that your module is using the WPFToolkit; based on my understanding, it seems that these assemblies might be referencing the Microsoft.Windows.Design.Extensibility.dll.

As a possible approach you could try adding the WPFToolkit assemblies as a reference to your main project as it seems that these assemblies should also be located in the solution output folder.

Also, you might find the following thread useful which contains more information related to this problem:

I hope you find this handy,

Agustin Adami
http://blogs.southworks.net/aadami


Apr 5, 2012 at 8:45 AM

no, that doesn't help,

what helps is adding reference to Microsoft.Windows.Design.Extensibility

but then it asks for Microsoft.Windows.Design.Interaction.PrimarySelectionContextMenuProvider which I don't know where to get from

Developer
Apr 9, 2012 at 5:51 PM

Hi,

If you are able to reproduce this undesired behavior in isolation, it would be helpful if you could provide us with a repro sample application; so that we can help you further with this.

On the other hand, you could check the following thread, which I believe might be helpful to clarify why this assembly is being loaded in your application:

Regards,

Agustin Adami
http://blogs.southworks.net/aadami