Load Modules

Topics: Prism v2 - WPF 3.5
Jan 14, 2010 at 10:19 AM

Hi. I have a problem using Microsoft.Practices.Composite.Modularity. My main WPF project have app.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="modules" type="Microsoft.Practices.Composite.Modularity.ModulesConfigurationSection, Microsoft.Practices.Composite"/>
  </configSections>
  <modules>
   <module assemblyFile="ShedulerClientService.dll" moduleType="ShedulerClientService.ModuleDefinitions.ServiceModule, ServiceModule, Version=1.0.0.0, Culture=neutral, PublicKeyToken=dfc9b8d5-4e6d-4d3f-aef3-58af0e91913d" moduleName="ServiceModule"/>
    <module assemblyFile="ShedulerClientGridUI.dll" moduleType="ShedulerClientGridUI.ModuleDefinitions.UIModule, UIModule, Version=1.0.0.0, Culture=neutral, PublicKeyToken=3b493226-cf8a-4338-98f1-d6a7eecc04a7" moduleName="UIModule">
      <dependencies>
        <dependency moduleName="ServiceModule"/>
      </dependencies>
    </module>
  </modules>
</configuration>

It cause error in:

protected virtual bool ModuleNeedsRetrieval(ModuleInfo moduleInfo)
{ bool isAvailable = Type.GetType(moduleInfo.ModuleType) != null;

exception: The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)

If to change app.config on:

    <module assemblyFile="ShedulerClientService.dll" moduleType="ShedulerClientService.ModuleDefinitions.ServiceModule, ServiceModule" moduleName="ServiceModule"/>
    <module assemblyFile="ShedulerClientGridUI.dll" moduleType="ShedulerClientGridUI.ModuleDefinitions.UIModule, UIModule" moduleName="UIModule">

It cause error in:

public virtual void HandleModuleInitializationError(ModuleInfo moduleInfo, string assemblyName, Exception exception)

exception: Unable to retrieve the module type ShedulerClientService.ModuleDefinitions.ServiceModule, ServiceModule from the loaded assemblies.  You may need to specify a more fully-qualified type name.

How it may be corrected?

Jan 19, 2010 at 4:54 PM

Hi,

Without knowing your entire application’s scenario, the second error you are getting could be because the Fully Qualified Type Name being used in the configuration file is not accurate. I was able to reproduce this same issue using the Configuration Modularity QS, and replacing the following line:

<module assemblyFile="Modules/ModuleB.dll" moduleType="ModuleB.ModuleB, ModuleB" moduleName="ModuleB"/>

with this one:

<module assemblyFile="Modules/ModuleB.dll" moduleType="ModuleB.ModuleB, Moduleeeeeeee" moduleName="ModuleB"/>

This article from the MSDN documentation explains how to get the required name. Take into account that the second approach you used is correct as the Version, Culture and PublicKeyToken of the assembly are not necessary as explained in this article from the Prism documentation.

Please let me know if this helps.

Damian Schenkelman
http://blogs.southworks.net/dschenkelman

Jan 24, 2010 at 12:00 PM

Thanks. Works only with:

<modules>
    <module assemblyFile="ShedulerClientService.dll" moduleName="ServiceModule" moduleType="ShedulerClientService.ModuleDefinitions.Module, ShedulerClientService"/>
    <module assemblyFile="ShedulerClientGridUI.dll" moduleName="GridUIModule" moduleType="ShedulerClientGridUI.ModuleDefinitions.Module, ShedulerClientGridUI">
      <dependencies>
        <dependency moduleName="ServiceModule"/>
      </dependencies>
    </module>
  </modules>

Where ShedulerClientGridUI.ModuleDefinitions { public class Module : IModule }  and ShedulerClientService.ModuleDefinitions { public class Module: IModule }