module depends on an OnDemand module loading error

Topics: Prism v4 - Silverlight 4
Mar 28, 2012 at 6:38 PM


I have a module which is loaded OnDemand (Parent).  There is another module which DependsOn this OnDemand module(Child).

In the module catalog I set the Child as InitializationMode="WhenAvailable". Now this does not work. And I kind of understand why it does not but it is the Error message which intrigues me and I wondered if anyone can explain what it's really saying: (and hopfully prove that is does work and that I am just missing something - apart from the obvious brain thing!)

 ErrMsg: Module Child is marked for automatic initialization when the application starts, but it depends on modules that are marked as OnDemand initialization. To fix this error, mark the dependency modules for InitializationMode=WhenAvailable, or remove this validation by extending the ModuleCatalog class.

  1. mark the dependency modules for InitializationMode=WhenAvailable
    I thought I had!
    <prism:ModuleInfo Ref="Child.xap"
                            Version=, Culture=neutral, PublicKeyToken=null"
    So what does the statemenat in the error message actually mean? Is it talking about the parent?
  2.  remove this validation by extending the ModuleCatalog class.
    Does anyone no of any blogs or tutorials which demponstrate how to do this?

When set up the module catalog up this way I had hoped that dependant modules(Children) would be loaded when the onDemand Parent was loaded.

I am guessing the solution is to manually load the children.  Do I have to use module tracking to ensure that the parent has loaded before loading any dependant modules? or can I go ahead and load them all parent and children in the one For Loop?




Mar 29, 2012 at 3:08 PM


Based on my understanding this error is thrown because one of the validation used by the default implementation of the ModuleCatalog provided by Prism.

As explained in the comments of the ModuleCatalog class, this implementation among other things verifies that there are no Invalid dependencies, such as a Module that's loaded at start up that depends on a module that might need to be retrieved. In my opinion the team considered that all modules loaded at start up might have all its dependencies loaded as well (on start-up).

Therefore to avoid this error, as the message explains you could change your module dependency ("ParentModule") to InitializationMode="WhenAvailable". Or as mentioned remove the aforementioned validation by extending the  ModuleCatalog class.

As explained in Appendix E: Extending Prism,Adding Features to the Module Catalog:

There are several ways to extend the functionality of the ModuleCatalog:

  • Derive from ModuleCatalog. If you need to change the behavior of ModuleCatalog, derive a new class and override one of the virtual methods.
  • Write extension methods on IModuleCatalog. If you need additional functionality in your application where you use IModuleCatalog, write an extension method on the interface.
  • Write extension methods on ModuleCatalog. If you need additional functionality, but only in places where you use ModuleCatalog, write an extension method on the concrete type.

Hence, I believe you could created a CustomModuleCatalog class according to the requirements of your scenario. In which, you could derive from the default ModuleCatalog class, and for example override the Validate() method of this class, changing how you want the validation to be done, for example like in the following code snippet:

public override void Validate()

            //I Commented this line as an example to remove the aforementioned validation
            //  this.ValidateDependenciesInitializationMode();

            this.Validated = true;

Then, once you have your CustomModuleCatalog you can override the CreateModuleCatalog method in your bootstrapper in order to create your own module catalog class,for example like this:

protected override IModuleCatalog CreateModuleCatalog()
         return  CustomModuleCatalog.CreateFromXaml(new Uri("/Prism.Workshop.Shell;component/ModulesCatalog.xaml", UriKind.Relative));

I hope you find this handy,

Agustin Adami

Mar 29, 2012 at 3:36 PM

What an awsome answer. Thank you vey much.

Best regards