Modules not loading

Topics: Prism v4 - Silverlight 4
Nov 2, 2010 at 10:24 PM

I've posted about a project I'm working on and the code.  It's a modular SL 4 app using a xaml file to specify the modules to load.

Today I created a new module, have it setup with the basics.  Added it to my config file.

I've looked in the Bootstrapper and the module appears to be loaded as I can see the exports from the module.  But the module constructor or Initialize isn't firing.

The module is defined as follows:

    [ModuleExport(typeof(ScanningModule), InitializationMode = InitializationMode.WhenAvailable)]
    public class ScanningModule : IModule


It's entry in the config file.

    <Modularity:ModuleInfo Ref="EyeCue.Modules.Scanning.xap"
                ModuleType="EyeCue.Modules.Scanning.ScanningModule, EyeCue.Modules.Scanning, Version=, Culture=neutral, PublicKeyToken=null" />

The question is how do we troubleshoot why a module isn't loading when

protected override void InitializeModules()

is used.



Nov 3, 2010 at 4:25 PM


I think that you can find the following forum threads interesting, since other users with a similar scenario found the solution:

Hope this helps.

Fernando Antivero


Nov 4, 2010 at 2:38 AM

Thanks Fantivero for the response.  I've really got to get this one figured out.

FYI.  This is my 3rd module I'm adding to the project.  The first two have worked flawlessly and I created this one the

Thread one doesn't apply as I have that set and the .xap file is showing up in the Web project.  I've actually removed it and readded etc just to make sure. 

Just about an hour ago, I decided to figure out what the CallbackLogger does.  So I created a class and wired it up in the bootstrapper and set a break point in the log method.  To my surprise there is an exception message coming back.  I don't understand why if there is an exception, the ModuleManager isn't rethrowing it so get notified of the problem.

Now to the info.  It looks to be MEF related at first look but it just doesn't make sense.

First here is the exception message.

Microsoft.Practices.Prism.Modularity.ModuleInitializeException: An exception occurred while initializing module 'ScanningModule'.
    - The exception message was: The composition remains unchanged. The changes were rejected because of the following error(s): The composition produced multiple composition errors, with 6 root causes. The root causes are provided below. Review the CompositionException.Errors property for more detailed information.

1) Change in exports prevented by non-recomposable import 'EyeCue.ShellViewModel.PopupController (ContractName="EyeCue.Common.IPopupController")' on part 'EyeCue.ShellViewModel'.

2) Change in exports prevented by non-recomposable import 'EyeCue.ShellController..ctor (Parameter="logService", ContractName="EyeCue.Common.ILogService")' on part 'EyeCue.ShellController'.

3) Change in exports prevented by non-recomposable import 'EyeCue.ShellController..ctor (Parameter="popupController", ContractName="EyeCue.Common.IPopupController")' on part 'EyeCue.ShellController'.

4) Change in exports prevented by non-recomposable import 'EyeCue.Modules.AppSettings.AppSettingController..ctor (Parameter="popupController", ContractName="EyeCue.Common.IPopupController")' on part 'EyeCue.Modules.AppSettings.AppSettingController'.

5) Change in exports prevented by non-recomposable import 'EyeCue.ShellController..ctor (Parameter="logService", ContractName="EyeCue.Common.ILogService")' on part 'EyeCue.ShellController'.

6) Change in exports prevented by non-recomposable import 'EyeCue.ShellController..ctor (Parameter="popupController", ContractName="EyeCue.Common.IPopupController")' on part 'EyeCue.ShellController'.


What doesn't make sense is it states my new ScanningModule failed but the compostion errors are with EyeCue.ShellViewModel.PopupController.

PopupController is defined in my EyeCue.Common assembly where all shared items are created.  In the bootstrapper, after I call the CreateFromXaml here

protected override IModuleCatalog CreateModuleCatalog()
            IModuleCatalog _modCat = Microsoft.Practices.Prism.Modularity.ModuleCatalog.CreateFromXaml(new Uri(ModuleCatalogUri, UriKind.Relative));
            return _modCat;


As we've went into in another thread in my dealings with Modules, for Exports to be available I have to override CreateContainer.

protected override CompositionContainer CreateContainer()
            var _container = base.CreateContainer();
            this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(Bootstrapper).Assembly));
            this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(GlobalValues).Assembly));


            return _container;


My new ScanningModule is plain right now.  It has a Module that Imports a Controller class which has a constructor that uses ImportConstructor.

It imports IPopupController. 

public ScanningController(IRegionManager regionManager, ScanningRootTemplateView scanningRootTemplateView, ScanningMainView scanningMainView, IPopupController popupController)

So for testing I remove popupController but I'm still getting the same exception and now my other modules are throwing an exception of the same type.

It doesn't make sense.  I have 3 modules now.  The previous 2 were TruckStat & Appsettings.  (I've abbreviated the full names)

They each have a controller that fires on load up.  Their controller's constructor's also import IPopupController and they worked fine.

It's almost like this module is causing a new DeploymentCatalog created or obviously it's causing PopupController part to change but it doesn't make sense how or why.

I've even removed the ImportConstructor in my new ScanningModule and I'm still getting the same exceptions

I don't understand how the other modules don't initiate this problem but this one does.

Nov 10, 2010 at 7:45 PM


Based on my understanding you might continue experiencing an issue when loading modules in your application. So, if you do, could you please provide a repro sample?

Fernando Antivero

Nov 10, 2010 at 7:50 PM

The app I'm working in is too large to create a repro.!229

contains a sample.  Just add another module assembly and you should see the problem.

I've actually worked around this by utilizing an ImportMany on the things I've described above but I only had to do them in the Main Silverlight app and don't have to do them in any of my modules that import the same part.

So why would just adding a module cause this change in behavior?

More concerning is why an exception isn't getting thrown when a module doesn't load?  I shouldn't have to have a debugger connected sifting through the ILoggerFacade to try and determine the problem.