Null error while Adding a Global service in a Foundational Module

Dec 17, 2008 at 5:30 PM
I have a Foundational Module 'Reports' in which I would like to add global services.
I get a null reference error in the ModuleInitializer class at the line underlined below -- AddGlobalServices(container.Parent.Services). container.Parent is not set so its null.

Please see the code snippet below.

public override void Load(CompositionContainer container)<o:p></o:p>






In the Web.config the module definition is a shown below:



      <module name="Shell" assemblyName="Shell" virtualPath="~/" />

      <module name="Reports" assemblyName="GSBAU.Reports">


          <dependency module="Shell" />









I am not sure why the Parent propery of the container is not set to the RootContainer.
I appreciate any suggestions.


Dec 18, 2008 at 4:06 PM
Edited Dec 18, 2008 at 4:19 PM

Hi Saru,


The reason why the Parent property of the container in a Foundational Module is null is because it is the RootContainer (does not have any parent). Foundational Modules do not have a module specific container like the Business Modules, so they always use the RootContainer (you can only add Global Services). So, if you want to add Global Services from your Foundational Module you should use the container.Services property.


When you use the Guidance Package, and execute the “Add Foundational Module” recipe, the Load method of the ModuleInitializer class looks like the following:


public override void Load(CompositionContainer container)







Based in your code snippet, it looks like you copied and refactored the code from a Business Module. You should not do that because when a Business Module is initialized by CWAB, a new child container is created (which has the Parent property set to the root container) and associated to the virtualPath of the module. Instead, when a Foundational Module is initialized by CWAB, like I said, the application’s root container is associated to it (which has the Parent property set to null).


Perhaps, you may want to try replacing your code with the one above.


Please, let me know if this helps.


Ezequiel Sculli