This project is read-only.

First Application with PRISM4

Jan 25, 2011 at 12:27 PM

Dear All,

I have reched PRISM after a lot of reading amd decided to use it as a framework to develop my new Silverlight 4 application.

I layout my project into 5 different projects, then I define the module catalog as follows:

the cataloge xaml file :- 

<Modularity:ModuleCatalog xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
	xmlns:sys="clr-namespace:System;assembly=mscorlib" 
	xmlns:Modularity="clr-namespace:Microsoft.Practices.Prism.Modularity;assembly=Microsoft.Practices.Prism">

	<Modularity:ModuleInfoGroup Ref="GL.Modules.AVT.xap" InitializationMode="WhenAvailable">
		<Modularity:ModuleInfo ModuleName="AVTModule"/>
	</Modularity:ModuleInfoGroup>

</Modularity:ModuleCatalog>
Then, I build the AVTModel class into the AVT project as follows:
namespace GL.Modules.AVT
{
	[ModuleExport(typeof(AVTModule))]
	public class AVTModule : IModule
	{
		[Import]
		public IRegionManager RegionManager;

		public void Initialize()
		{
			RegionManager.RegisterViewWithRegion(RegionNames.MainNavigationRegion, 
						typeof(Views.CurrencyNavigationItemView));
		}
	}
}
And also defined the bootstrapper class as follows:
	public class GlBootStrapper : MefBootstrapper
	{
       private const string ModuleCatalogUri = "/GL;component/ModulesCatalog.xaml";

		protected override DependencyObject CreateShell()
		{
			return this.Container.GetExportedValue<Shell>();
		}
		protected override void InitializeShell()
		{
			base.InitializeShell();
			Application.Current.RootVisual = (UIElement)this.Shell;
		}
		protected override IModuleCatalog CreateModuleCatalog()
		{
			return Microsoft.Practices.Prism.Modularity.ModuleCatalog.CreateFromXaml(
																				new Uri(ModuleCatalogUri, UriKind.Relative));
		}
		protected override void ConfigureAggregateCatalog()
		{
			base.ConfigureAggregateCatalog();

			this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(GlBootStrapper).Assembly));
		}

	}
When I run the application I got an exception as follows:

Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; GTB6.6; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET4.0C; .NET4.0E)
Timestamp: Tue, 25 Jan 2011 12:24:34 UTC


Message: Unhandled Error in Silverlight Application
Code: 4004   
Category: ManagedRuntimeError      
Message: Microsoft.Practices.Prism.Modularity.ModuleTypeLoadingException: Failed to load type for module AVTModule.

If this error occurred when using MEF in a Silverlight application, please ensure that the CopyLocal property of the reference to the MefExtensions assembly is set to true in the main application/shell and false in all other assemblies.

Error was: The package downloaded successfully but an error occurred while reading the contents of the package. See the inner exception for more details.. ---> System.InvalidOperationException: The package downloaded successfully but an error occurred while reading the contents of the package. See the inner exception for more details. ---> System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
   at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
   at System.Reflection.RuntimeModule.GetTypes()
   at System.Reflection.Assembly.GetTypes()
   at System.ComponentModel.Composition.Hosting.AssemblyCatalog.get_InnerCatalog()
   at System.ComponentModel.Composition.Hosting.AssemblyCatalog.get_Parts()
   at System.ComponentModel.Composition.Hosting.DeploymentCatalog.DiscoverParts(IEnumerable`1 assemblies)
   at System.ComponentModel.Composition.Hosting.DeploymentCatalog.HandleOpenReadCompleted(Object sender, OpenReadCompletedEventArgs e)
   --- End of inner exception stack trace ---
   --- End of inner exception stack trace ---
   at Microsoft.Practices.Prism.Modularity.ModuleManager.HandleModuleTypeLoadingError(ModuleInfo moduleInfo, Exception exception)
   at Microsoft.Practices.Prism.Modularity.ModuleManager.IModuleTypeLoader_LoadModuleCompleted(Object sender, LoadModuleCompletedEventArgs e)
   at Microsoft.Practices.Prism.MefExtensions.Modularity.MefXapModuleTypeLoader.RaiseLoadModuleCompleted(LoadModuleCompletedEventArgs e)
   at Microsoft.Practices.Prism.MefExtensions.Modularity.MefXapModuleTypeLoader.RaiseLoadModuleCompleted(ModuleInfo moduleInfo, Exception error)
   at Microsoft.Practices.Prism.MefExtensions.Modularity.MefXapModuleTypeLoader.HandleDownloadCompleted(DeploymentCatalog deploymentCatalog, AsyncCompletedEventArgs e)
   at Microsoft.Practices.Prism.MefExtensions.Modularity.MefXapModuleTypeLoader.DeploymentCatalog_DownloadCompleted(Object sender, AsyncCompletedEventArgs e)
   at System.ComponentModel.Composition.Hosting.DeploymentCatalog.OnDownloadCompleted(AsyncCompletedEventArgs e)
   at System.ComponentModel.Composition.Hosting.DeploymentCatalog.HandleOpenReadCompleted(Object sender, OpenReadCompletedEventArgs e)
   at System.Net.WebClient.OnOpenReadCompleted(OpenReadCompletedEventArgs e)
   at System.Net.WebClient.OpenReadOperationCompleted(Object arg)    

Line: 56
Char: 13
Code: 0
URI: http://localhost:4692/GLTestPage.aspx

 

I already checked the Mef assembly copy local is false in the other project !!

 

What could be the reason of this error ..

Thanks and best regards

Waleed