Exception when run the View Switching QuickStart

Topics: Prism v4 - Silverlight 4
Mar 25, 2013 at 9:51 PM
I am a fresher for PRISM. I hope I can get help from here regarding an exception I got when I run the View-Switching Navigation QuickStart from the folder \Source\Quickstarts\View-Switching Navigation\Silverlight\View-Switching Navigation.

The exception message said "An Unhandled Exception('Unhandle Exception SliverLight Appliction...) Code 4004. ModuleTypeLoadingException.

It seems like an exception regarding the Module Loading.
I didn't change anything in the solution, and the following is the xaml file(ModulesCatalog.xaml):

<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="ViewSwitchingNavigation.Contacts.xap" InitializationMode="WhenAvailable">
    <Modularity:ModuleInfo ModuleName="ContactsModule"/>
</Modularity:ModuleInfoGroup>
<Modularity:ModuleInfoGroup Ref="ViewSwitchingNavigation.Email.xap" InitializationMode="WhenAvailable">
    <Modularity:ModuleInfo ModuleName="EmailModule" />
</Modularity:ModuleInfoGroup>
<Modularity:ModuleInfoGroup Ref="ViewSwitchingNavigation.Calendar.xap" InitializationMode="WhenAvailable">
    <Modularity:ModuleInfo ModuleName="CalendarModule"/>
</Modularity:ModuleInfoGroup>
</Modularity:ModuleCatalog>

It looks correct to me.

Any suggestion with the exception are welcome and appreciated.

BTW, the environment I open the solution is PRISM 4/.Net 4/ SL 5, and I also tried change the target SL version to SL4, doesn't work and more errors about reference.

Thanks,
Kevin
Developer
Mar 26, 2013 at 6:25 PM
Hi Kevin,

I just tested the View-Switching Navigation QuickStart of Prism 4 (with Silverlight 4) and of Prism 4.1 (with Silverlight 5) and both worked correctly as out of the box.

As a starting point to understand the cause behind this problem, you could check the exception in order to find more details about why the QuickStart is failing. To do so, you need to:
  1. Enable Silverlight debugging in the Web project: go to ViewSwitchingNavigation.Web's properties > Web > Debuggers > check the Silverlight option.
  2. Put a break point in the Application_UnhandledException method of the App.xaml.cs class of the ViewSwitchingNavigation project.
Then, when you run the QuickStart again, you should be able to find the exception in the ExceptionObject property of the e parameter. Please post your findings so that we can help you further with this.

As a side note, take into account that if you are using Silverlight 5 it's recommended to use the Prism 4.1 version instead of the Prism 4 version.

Regards,

Damian Cherubini
http://blogs.southworks.net/dcherubini
Mar 27, 2013 at 10:12 AM
Edited Mar 27, 2013 at 10:23 AM
Hi Damian,

Thanks for your reply. I tested the solution at other PC with Windows 2008 Server( and PRISM 4/.Net 4/ SL 5). It works well. Following your suggestion, I got the exception message as below.

And I also checked the CopyLocal property of the reference to the MefExtensions in all the assemblies.

Thanks.
  • [Microsoft.Practices.Prism.Modularity.ModuleTypeLoadingException] {Microsoft.Practices.Prism.Modularity.ModuleTypeLoadingException: Failed to load type for module CalendarModule.
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: An exception occurred during a WebClient request.. ---> System.Net.WebException: An exception occurred during a WebClient request. ---> System.NotSupportedException: The URI prefix is not recognized.
at System.Net.WebRequest.Create(Uri requestUri)
at System.Net.WebClient.GetWebRequest(Uri address)
at System.Net.WebClient.OpenReadAsync(Uri address, Object userToken)
--- 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)} Microsoft.Practices.Prism.Modularity.ModuleTypeLoadingException
Developer
Mar 27, 2013 at 10:22 PM
Hi Kevin,

I tried to find the cause behind this problem and found that this same exception is thrown if the ViewSwitchingNavigation.Web project is not set as the entry point of your application.

Just as a quick test, please check that that the ViewSwitchingNavigation.Web project is selected as the StartUp Project. If not, please select it doing right click on the project and then click on the Set as StartUp Project option.

Regards,

Damian Cherubini
http://blogs.southworks.net/dcherubini
Mar 28, 2013 at 9:44 AM
Thanks Damian. As your suggestion, I works well. It is a shame and thanks a lot for your help.

Regards,
Kevin