Prism Cannot load module via config (v 4 drop 6) What Am I doing wrong?

Topics: Prism v4 - WPF 4
Sep 7, 2010 at 6:13 PM
 0 down vote favorite
 

Hi all Learning prism and and I am now trying the various way you can load Modules. I cannot get to Load the Modules when defined in the configuration. It loads but it does not show my "Hello world " View/string If I add a project Reference to the PrismTutorials.HelloWorldModule.dll and add this piece of code it all works

protected override void ConfigureModuleCatalog()
    {
        base.ConfigureModuleCatalog();
        // Module is defined in the code.
        ModuleCatalog moduleCatalog = (ModuleCatalog) ModuleCatalog;
        moduleCatalog.AddModule(typeof(HelloWorldModule.HelloWorldModule));
    }

The Following does not work:

What Am I doing wrong when I use the configuration? Thanks for any suggestions

This is what I have: 2 Dlls PrismTutorials.HelloWorld.Desktop.dll

  • Shell Bootstrapper etc...

PrismTutorials.HelloWorldModule.dll

  • HelloWorldModule.cs etc...

 

App.Config

  <?xml version="1.0"?> 
  <configuration> 
    <configSections> 
   <section name="modules"  
      type="Microsoft.Practices.Prism.Modularity.ModulesConfigurationSection, Microsoft.Practices.Prism"/> 
    </configSections> 
    <modules>    
   <module assemblyFile="PrismTutorials.HelloWorldModule.dll" 
     moduleType="PrismTutorials.HelloWorldModule, PrismTutorials.HelloWorldModule, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" 
     moduleName="HelloWorldModule" 
     startupLoaded="false" /> 
    </modules> 
  </configuration> 
Bootstrapper public class Bootstrapper : UnityBootstrapper 
{ 
    protected override DependencyObject CreateShell() 
{  
   return this.Container.Resolve(); 
} 
protected override void InitializeShell() 
{ 
    base.InitializeShell();

 Application.Current.MainWindow = (Window)Shell; 
 Application.Current.MainWindow.Show(); 
} 
 
 
protected override IModuleCatalog CreateModuleCatalog() 
{ 
 return new ConfigurationModuleCatalog(); 
} 
}

Can you spot what Am I doing wrong when loading via config file?

Thanks  a lot

 

Sep 8, 2010 at 12:43 AM

Sorry you had difficulty getting this to work.

I have just downloaded the last drop of Prism (http://compositewpf.codeplex.com/releases/view/51993) and opened the ..\Quickstarts\Hello World\HelloWorld.Desktop solution.

I made the same code changes you did and set up my config file as below.

Notice that I have the startupLoaded="true"  This will cause the module to be loaded at start up.

You may also have an issue with your moduleType value.  In the below example the Assembly is HelloWorldModule, the namespace is HelloWorldModule and the type name is HelloWorldModule.

<?xml version="1.0"?>
<configuration>
  <configSections>
    <section name="modules"
       type="Microsoft.Practices.Prism.Modularity.ModulesConfigurationSection, Microsoft.Practices.Prism"/>
  </configSections>
  <modules>
    <module assemblyFile="HelloWorldModule.dll"
      moduleType="HelloWorldModule.HelloWorldModule, HelloWorldModule, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
      moduleName="HelloWorldModule"
      startupLoaded="true" />
  </modules>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client"/>
  </startup>
</configuration>

Have a great day,

Karl

Sep 8, 2010 at 6:56 AM

Karl
I am a great admirer of your tutorials ,they are fantastic.Happily using your xaml powertoys .What a Time saver.

Still no joy and now I get an interisting error as I have changed to startupLoaded="true" .

"Microsoft.Practices.Prism.Modularity.ModuleTypeLoadingException was unhandled
  Message=Failed to load type for module HelloWorldModuleTestClass. Error was: Unable to retrieve the module type PrismTutorials.HelloWorldModule, PrismTutorials.HelloWorldModule, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null from the loaded assemblies.  You may need to specify a more fully-qualified type name..
  Source=Microsoft.Practices.Prism
  ModuleName=HelloWorldModuleTestClass"
 


I thought I had checked everything but obviously not.
I have recreate the HelloWorldModule from scratch as a learning process and called PrismTutorials.HelloWorldModule
I have changed the name of my type for clarity  from HelloWorldModule to HelloWorldModuleTestClass.

Assembly   =PrismTutorials.HelloWorldModule.dll
Namespace  =PrismTutorials.HelloWorldModule
ModuleName =HelloWorldModuleTestClass

Steps
  1) Config
  

<?xml version="1.0"?>
  <configuration>
    <configSections>
   <section name="modules" 
      type="Microsoft.Practices.Prism.Modularity.ModulesConfigurationSection, Microsoft.Practices.Prism"/>
    </configSections>
    <modules>   
   <module assemblyFile="PrismTutorials.HelloWorldModule.dll"
     moduleType="PrismTutorials.HelloWorldModule, PrismTutorials.HelloWorldModule, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
     moduleName="HelloWorldModuleTestClass"
     startupLoaded="true" />
    </modules>

    
   2) Created Folder called Modules in "D:\Prism\Tutorials\Projects\PrismTutorials.HelloWorld.Desktop\bin\Debug\Modules"
      Set output Path to ..\PrismTutorials.HelloWorld.Desktop\bin\Debug\Modules\
   Checked and the dll is inside this folder
</configuration>
 
  3) Run and get error
     "Microsoft.Practices.Prism.Modularity.ModuleTypeLoadingException was unhandled
  Message=Failed to load type for module HelloWorldModuleTestClass. Error was: Unable to retrieve the module type PrismTutorials.HelloWorldModule, PrismTutorials.HelloWorldModule, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null from the loaded assemblies.  You may need to specify a more fully-qualified type name..
  Source=Microsoft.Practices.Prism
  ModuleName=HelloWorldModuleTestClass"
  Cannot see what I am doing wrong
  
  So
  I have gone back to the original quick start added your config file
  and Got the "Unable to find specified file"
  Did you create a directory and set up some build events ?
 
  Sorry for lengthy reply.But I thought it would help you to help me.
  Thanks a lot

Sep 11, 2010 at 8:20 AM

Managed to get it working.

I had to change the config file as follows since I had  folder called modules

<?xml version="1.0"?>
<configuration>
  <configSections>
    <section name="modules" 
             type="Microsoft.Practices.Prism.Modularity.ModulesConfigurationSection, Microsoft.Practices.Prism"/>
  </configSections>
  <modules>
    <module assemblyFile="Modules/PrismTutorials.HelloWorldModule.dll"
            moduleType="PrismTutorials.HelloWorldModule.HelloWorldModuleTestClass, PrismTutorials.HelloWorldModule, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
            moduleName="HelloWorldModule"
      startupLoaded="true" />
  </modules>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client"/>
  </startup>
  
</configuration>