Module Load fails with mef (CreateModule cannot find ModuleInfo)

Topics: Prism v4 - WPF 4
Jul 7, 2011 at 12:23 AM

Hi All,

I am a newbie to Prism. Using MefBootStrapper I am trying to get my first module to load. In my app.config I have:

 

 

<modules> 

   <module assemblyFile="DashBoard.dll" moduleType="DashBoard.DashBoardModule, DashBoard.DashBoardModule, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" moduleName="DashboardModule" />

</modules>

 

 

In my module dll I have:

 

 

   [ModuleExport( typeof( DashBoardModule ) )]

   public class DashBoardModule : IModule

   {

       public DashBoardModule()

       {

           Console.WriteLine( "In constructor" )

       }

 

       public void Initialize()

       {

           Console.WriteLine( "In initialize" )

       }

   }

 

My application starts and the shell is displayed then the following happens

 

1)      ModuleManager.Run calls LoadModulesWhenAvailable

2)      Then the first call to ModuleInitializer.CreateModule occurs with my ModuleInfo

3)      In CreateModule the TryGet if is not executed

           if (this.downloadedPartCatalogs.TryGet(moduleInfo, out partCatalog))

 

but ImportedModueles if is executed which returns IModule for my module

 

           if (this.ImportedModules != null && this.ImportedModules.Count() != 0)

           {

           Lazy<IModule, IModuleExport> lazyModule = this.ImportedModules.FirstOrDefault(…);

               if (lazyModule != null)

               {

                   return lazyModule.Value;

               }

           }

4)      My module initialize returns successfully which raises LoadModuleCompleted

5)      After that ModuleManager.IModuleTypeLoader_LoadModuleCompleted which calls ModuleInitialer.CreateModule again

6)      In second call to CreateModule neither the TryGet if or ImportedModules if are executed and the exception ModuleInitializeException is thrown

 

So I think the ModuleManager tries to retrieve the ModuleInfo after the first call to CreateModule but for some reason this fails. I have looked at this thread:

Module Loading Error (http://compositewpf.codeplex.com/discussions/247248)

The author adds the following and says it gets around his error:

 Type type = Type.GetType(moduleInfo.ModuleType, false, true);

 but I am not sure if this relates to my error. Also I have studied the quick start ModularityWithMef.Desktop, and used some of its code. If anyone could provide any input why ModuleInfo is not found in CreateModule I would appreciate it.

 

Jul 7, 2011 at 12:49 AM

I forgot to add the DashBoardModule is in the DashBoard namespace.