1
votes

When my Prism 6 WPF modular application using Unity is starting then "Prism.Modularity.ModuleTypeLoadingException" in Prism.Wpf.dll is thrown. Below is screen shot of the exception:

enter image description here

As you can see the exception throws when Bootstrepper.Run method is called. Below is the code of the Botstrapper:

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

        protected override void InitializeShell()
        {
            Application.Current.MainWindow.Show();
        }

        protected override IModuleCatalog CreateModuleCatalog()
        {
            return new ConfigurationModuleCatalog();
        }
    }
}

Solution of my application consists of three projects: main WPF project created with Prism Template Pack as Prism Unity App and two modules, each of which is created with Prism Template Pack as Prism Module. Both of the modules are registered in App.config file, please see below:

<?xml version="1.0" encoding="utf-8" ?>
   <configuration>
      <configSections>
          <section name="modules" type="Prism.Modularity.ModulesConfigurationSection, Prism.Wpf"/>
      </configSections>
      <modules>
          <module assemblyFile="Authorization.dll" moduleType="Authorization.AuthorizationModule, Authorization, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" moduleName="AuthorizationModule" startupLoaded="true" />
          <module assemblyFile="Calibration.dll" moduleType="Calibration.CalibrationModule, Calibration, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" moduleName="CalibrationModule" startupLoaded="true" />
      </modules>
      <startup>
          <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
      </startup>
   </configuration>

The first module is called Authorization and its class is caled AuthorizationModule:

namespace Authorization
{
    [Module(ModuleName = "AuthorizationModule", OnDemand = false)]
    public class AuthorizationModule : IModule
    {
       . . . . .
    }
} 

The second module is called Calibration and its class is called CalibrationModule:

namespace Calibration
{
    [Module(ModuleName = "CalibrationModule", OnDemand = false)]
    public class CalibrationModule : IModule
    {
       . . . . .
    }
}

When my application is starting then MainWindow is displayed for short time (less then 1 second) and after this short time interval ModuleTypeLoadingException related to CalibrationModule is thrown. It looks like that type for AuthorizationModule was loaded succsessfully but loading of type for CalibrationModule fails. Please help me to eliminate this error.

P.S. I've not defined any instance of IModuleManager in my application. May be I must define it somewhere in my application?

3
With these informations it's really hard to guess what happened. I recommend you compare names in configuration file and dll you're trying to link.Fka
Are your dlls and exe in the same folder?galakt
There are FlowmeterConfiguration.exe and Microsoft's and Prism's dlls in folder 'D:\My_C#_Projects\FlowmeterConfiguration_Unity\FlowmeterConfigurator\FlowmeterConfigurator\bin\Debug'.Dr.Doog
Change the output path of your modules so they end up in the directory where the exe is (i.e. "..\TheApp\bin\debug\" instead of "bin\debug\", same for release), and add the modules as build dependencies to the exe project so they are actually built if you build the exe.Haukinger
I've added the references to the modules' dlls to the references list of shell project in solution and my application works!Dr.Doog

3 Answers

0
votes

Exception says that prism can`t find .dll files. Your .exe file and .dll files of modules should be in the same folder(according to your app.config in previous question);

0
votes

Exception says that prism can`t find .dll files. These may not been found if the diffrent projects of the solution are not build with the same Target Framework version. I had this error, when the Module-project was build in .Net Framework 4.5.2, while the Main-project was in 4.5.1. Correct/Align the Target Framework version, exit Visual Studio, reenter, rebuild. Then the error was gone.

Mostly there are a multitude of reasons for an Exception.

0
votes

.exe and .dll should be in same folder to avoid this exception that can be achieved in below two ways

1) Go to module project properties -> Build Events ->Post build event command line and paste the below code

copy "$(TargetPath)" "$(SolutionDir)MainWPFProject\bin\$(ConfigurationName)"

MainWPFProject in above code means project having App.config file.

2) Copy dependent module .dll manually