Modules not loading when silverlight hosted in html page

Topics: Prism v2 - Silverlight 4
Nov 18, 2012 at 11:17 PM


I'm currently working on a Silverlight 4 application, that's using Prism to load modules on application startup. I'm using a modules catalog, and the application is hosted in IIS (server via an aspx page).

I'm currently attempting a demo version of the application that does not require hosting by a webserver (such that a simple basic installer may be distrubuted to those performing the demo), so I'm using a html page rather than aspx. However, the modules do not load when using the html page (they load fine in the hosted aspx).

Any reason why modules will work fine when hosted, but fall part when used statically ?

Nov 19, 2012 at 5:36 PM


I believe this is related to how Silverlight works.

Based on my understanding, when opening a web page containing a Silverlight application it "downloads" the .xap file containing the Silverlight application and executes it. This is also true for a Silverlight-Prism application.

Then when Prism tries to load modules in a Silverlight application and those modules are stored in a different .xap file than the one containing the main project, they need to be "downloaded" as only the main .xap file was retrieved by the web page. In order to do this, Prism uses Silverlight's capabilities to obtain those .xap files and, based on my understanding, if the .xap files are not present if your browser's cache Silverlight will request them to its hosting server.

This seems to be where your application is failing. The main .xap file is loaded by the browser when the html page is opened. However, when the modules need to be loaded Silverlight tries to reach its hosting server to obtain them, but there is no server to respond its requests (in the hosted version, the requests are answered by the IIS server).

As a workaround, you could change your application for the demo version to have a reference to your modules' projects so that their assemblies are included in the main .xap file of your application. Take into account that you will also need to change your ModuleCatalog (specifically the Ref property of each module) as the assemblies will now be in the main .xap and not in their original ones.

I hope you find this useful,

Damian Cherubini

Nov 19, 2012 at 9:44 PM

I've already implement that workaround.

I was hoping to maintain the original architecture though, such that the demo software is no different to the release software.

Is it at all possible to use file references, or relative paths in the module catalog ? You can in WPF land ...

Nov 20, 2012 at 7:42 PM


As far as I know by default Prism does not provide this kind of functionality, as you may find the module retrieval strategy is defined by the XapModuleTypeLoader and the MefXapModuleTypeLoader classes provided with Prism. Both of these implementations achieve the downloading of XAP files by using a WebClient (which requires the Silverlight control to be hosted in a web page), in the case of Unity this logic is defined in the FileDownloader class and in MEF the DeploymentCatalog class is used to download .xap files and discover the assemblies and types within those .xap files.

Hence, as a possible approach, you could try extending this behavior by implementing your custom IModuleTypeLoader. For more information about this and how to achieve extending Prism's functionalities, you could check the following chapter of the documentation:

However, take into account that unlike WPF, the Silverlight security model does not allow you to load assemblies from the file system, in which case in my opinion the workaround suggested by Damian Cherubini seems like a plausible approach.

I hope you find this handy,

Agustin Adami