remote module downloading in PRISM 2.2

Topics: Prism v2 - Silverlight 4
Jan 13, 2011 at 1:40 PM
Hi, I'm using PRISM 2.2 with SL4. I've have setup my solution which was working just fine till now. To cut it short, I' need to configure my ModulesCatalog.xaml for implementing modularity. First thing first I really haven't got clear understanding of Modularity:ModuleInfo child properties e.g. <Modularity:ModuleInfo Ref="Navigation.xap" InitializationMode="WhenAvailable" ModuleName="XYZ" ModuleType="ABC, EFG, Version=1.0.0.0"> can someone please clearify what XYZ, ABC, EFG means in the catalog xaml. its really very confusing even in quickstarts everything has the same value which further adds the misery. I'll be really thankful if anyone can precisely define each on of the aforementioned tentative values. Also, here is my catalog.xaml file which I'm trying to work with. <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.Composite.Modularity;assembly=Microsoft.Practices.Composite"> <Modularity:ModuleInfo Ref="Navigation.xap" InitializationMode="WhenAvailable" ModuleName="IST.Modules.Navigation" ModuleType="IST.Modules.Navigation.NavigationModule, IST.Modules.Navigation, Version=1.0.0.0"> </Modularity:ModuleInfo> <Modularity:ModuleInfo Ref="EPACore.xap" InitializationMode="OnDemand" ModuleName="IST.Modules.EPACore" ModuleType="IST.Modules.EPACore.EPACoreModule, IST.Modules.EPACore, Version=1.0.0.0" > <Modularity:ModuleInfo.DependsOn> <sys:String>IST.Modules.Navigation</sys:String> </Modularity:ModuleInfo.DependsOn> </Modularity:ModuleInfo> </Modularity:ModuleCatalog> Now as you can see I don't want to use any ModuleInfoGroup as I have different XAP being produced in my app. However these two modules are dependent so I've also tried to set my dependencies here. I'm not even sure whether I should even expect it to work. I'm getting this exception in my Application_UnhandledException handler. ExceptionObject {Microsoft.Practices.Composite.Modularity.ModuleTypeLoadingException: Failed to load type for module IST.Modules.Navigation. Error was: Object reference not set to an instance of an object.. ---> System.NullReferenceException: Object reference not set to an instance of an object. at Microsoft.Practices.Composite.Modularity.XapModuleTypeLoader.GetParts(Stream stream) at Microsoft.Practices.Composite.Modularity.XapModuleTypeLoader.OnDownloadCompleted(Object o, DownloadCompletedEventArgs e) --- End of inner exception stack trace --- at Microsoft.Practices.Composite.Modularity.ModuleManager.HandleModuleTypeLoadingError(ModuleInfo moduleInfo, Exception exception) at Microsoft.Practices.Composite.Modularity.ModuleManager.OnModuleTypeLoaded(ModuleInfo typeLoadedModuleInfo, Exception error) at Microsoft.Practices.Composite.Modularity.XapModuleTypeLoader.OnDownloadCompleted(Object o, DownloadCompletedEventArgs e) at Microsoft.Practices.Composite.Modularity.FileDownloader.WebClient_OpenReadCompleted(Object sender, OpenReadCompletedEventArgs e) at System.Net.WebClient.OnOpenReadCompleted(OpenReadCompletedEventArgs e) at System.Net.WebClient.OpenReadOperationCompleted(Object arg)} System.Exception {Microsoft.Practices.Composite.Modularity.ModuleTypeLoadingException} which in browser looks like: Webpage error details User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET4.0C; .NET4.0E) Timestamp: Thu, 13 Jan 2011 14:36:21 UTC Message: Unhandled Error in Silverlight Application Code: 4004 Category: ManagedRuntimeError Message: Microsoft.Practices.Composite.Modularity.ModuleTypeLoadingException: Failed to load type for module IST.Modules.Navigation. Error was: Object reference not set to an instance of an object.. ---> System.NullReferenceException: Object reference not set to an instance of an object. at Microsoft.Practices.Composite.Modularity.XapModuleTypeLoader.GetParts(Stream stream) at Microsoft.Practices.Composite.Modularity.XapModuleTypeLoader.OnDownloadCompleted(Object o, DownloadCompletedEventArgs e) --- End of inner exception stack trace --- at Microsoft.Practices.Composite.Modularity.ModuleManager.HandleModuleTypeLoadingError(ModuleInfo moduleInfo, Exception exception) at Microsoft.Practices.Composite.Modularity.ModuleManager.OnModuleTypeLoaded(ModuleInfo typeLoadedModuleInfo, Exception error) at Microsoft.Practices.Composite.Modularity.XapModuleTypeLoader.OnDownloadCompleted(Object o, DownloadCompletedEventArgs e) at Microsoft.Practices.Composite.Modularity.FileDownloader.WebClient_OpenReadCompleted(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:37782/EPATestPage.aspx Can someone tell me what am I doing wrong here? I'll be highly grateful. profound regards,
Developer
Jan 13, 2011 at 2:16 PM
Edited Jan 13, 2011 at 2:16 PM

Hi,

The ModuleInfo class defines metadata for describing a module. Hence, the ModuleName property is simply a name that identifies the module, while the ModuleType property is the module's AssemblyQualifiedName. Based on this information:

  • XYZ is your module's name, useful to identify your module
  • ABC is your module's type (i.e. the type of your IModule)
  • EFG is the assembly in which your module resides

Note that you should also include the Culture and the PublicKeyToken when defining the ModuleType, which could be neutral and null respectively, in case you don't want to specify a culture and/or have a signed assembly.

Also, as I've mentioned in your previous thread, you're specifying a relative path to the module's XAP file, so the XapModuleTypeLoader might be having trouble finding the file specified.

I hope you find this helpful.

Guido Leandro Maliandi
http://blogs.southworks.net/gmaliandi

Jul 29, 2011 at 1:12 PM

Hi,

I am using PRISM 4 and Silverlight 4. I have a main application and 2 modules both in seperate class libraries. All the xap files are built into the clientBin folder of the web container project.

Here is the implementation of the modulecatalog file i am using to load the modules in the Bootstrapper:

<?xml version="1.0" encoding="utf-8" ?>
<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:ModuleInfo
        Ref="ModuleAProject.xap"
        ModuleName="ModuleA"
        ModuleType="ModuleAProject.ModuleA, ModuleAProject,Version=1.0.0.0">
    </Modularity:ModuleInfo>
    <Modularity:ModuleInfo
        Ref="ModuleBProject.xap"
        ModuleName="ModuleB"
        ModuleType="ModuleBProject.ModuleB, ModuleBProject,Version=1.0.0.0">
        <Modularity:ModuleInfo.DependsOn>
            <sys:String>ModuleA</sys:String>
        </Modularity:ModuleInfo.DependsOn>
    </Modularity:ModuleInfo>
    <Modularity:ModuleInfo
        ModuleName="MainModule"
        ModuleType="CalculatorApplication.MainModule, CalculatorApplication,Version=1.0.0.0">
        <Modularity:ModuleInfo.DependsOn>
            <sys:String>ModuleB</sys:String>
        </Modularity:ModuleInfo.DependsOn>
    </Modularity:ModuleInfo>
</Modularity:ModuleCatalog>

 

When i try to run the project i get an error for ModuleA and ModuleB but the main module in the main application loads. The only way i can get this to work is to add a reference to ModuleA and ModuleB in the Main silverlight project. I have debugged down to the error and it is a problem with the URI and the IFileDownloader in the XapModuleTypeLoader. All of the xaps are definatley in the clientbin folder at runtime.

Here is the error message

e.Error = {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)

 

The URI is "ModuleAProject.xap" and URIKind is relativeOrabsolute

I can definitley see that xap in the clientbin at runtime.

Anyone know how i can fix this.

Developer
Jul 29, 2011 at 5:25 PM

Hi,

It would be helpful if you could provide us with a repro sample application that portrays this problem, so we can help you find out a way to avoid it.

Thanks,

Guido Leandro Maliandi
http://blogs.southworks.net/gmaliandi

Aug 2, 2011 at 1:48 PM

http://www.mediafire.com/download.php?qsvmeu8qi2j6wmx

Source code is above. With the 2 references in the CalculatorApplication to ModuleAProject and ModuleBProject the solution should run fine. Removing these references should throw a URI error when prism tries to load them from the relevent XAP.


Thanks

 

Developer
Aug 4, 2011 at 5:14 PM

Hi,

We've examined your repro sample application, and found that the problem was caused by the fact that you had your Shell project set as the startup project (the CalculatorApplication project). If you set the web project (the CalculatorApplication.Web project) as the startup project, the exception is not shown anymore.

I hope you find this helpful.

Guido Leandro Maliandi
http://blogs.southworks.net/gmaliandi

Mar 5, 2012 at 5:49 PM

Has this been resolved?  Offline Silverlight applications or those designed to be run without a web project don't have this option.  As it's an intermittent error, it's a development annoyance in the extreme. 

Is there a solution to this that does not involve creating a web project unnecessarily?

Developer
Mar 6, 2012 at 6:41 PM

Hi,

As far as I know, when downloading modules packaged in different XAP files, its required to launch the Silverlight application from a web page. Based on my understanding, I believe this is caused by the fact that the XAP files are downloaded through a WebClient, which (as explained in the WebClient class) requires the Silverlight control to be hosted in a web page.

This can be seen in the XapModuleTypeLoader (for Unity) and the MefXapModuleTypeLoader (for MEF) classes included in the Prism library. XapModuleTypeLoader uses the FileDownloader class to download XAP files through a WebClient. On the other hand, MefXapModuleTypeLoader uses the DeploymentCatalog class, which as far as I know, also uses a WebClient inside to retrieve the XAP files.

As a possible approach, you could try to extend the XapModuleTypeLoader and FileDownloader classes (if you are using Unity) or the MefXapModuleTypeLoader (if you are using MEF) in order to implement your custom logic to retrieve the required XAP files when running OOB or offline.

You can find more information about extending Prism in the following appendix of the Prism documentation:

I hope you find this useful,

Damian Cherubini
http://blogs.southworks.net/dcherubini

Developer
Mar 7, 2012 at 3:41 PM
Edited Mar 7, 2012 at 4:04 PM

Hi,

After reading your post again, I believe that I have misunderstood your question.

It seems that that the intermittent issue you are mentioning could be related to the problem described in the following thread:

As explained in the aforementioned thread by Guido Maliandi, this issue seems to appear when performing two web request simultaneously in a Silverlight OOB application with Cassini.

Also, according to the findings mentioned in that thread, this issue was reproduced in a Silverlight only application and therefore, it doesn't seem to be related to Prism.

I hope you find the suggestions provided in the aforementioned thread useful.

Damian Cherubini
http://blogs.southworks.net/dcherubini

Sep 17, 2013 at 6:13 AM
Also in our Silverlight application, intermittently, we see the same NullReferenceException in XapModuleTypeLoader.GetParts() which the OP reported. This is an in-browser application, when deployed: I've not seen this problem in a development environment.

Note that we don't see a NotFound error being reported-- but I have no network or HTTP trace of this error situation, so I don't know whether or not an HTTP error is sent back from the server.

In the one instance I've seen, this exception probably occurred the first time the Silverlight page was loaded after installing the application. And it seems to occur for each of the (many) .xap files in our application.

Any light?

Thanks!
Developer
Sep 17, 2013 at 7:07 PM
Hi,

If I understood correctly, when your Silverlight application is deployed in a web server this error does not appear; but when the application is locally installed in a machine you are experiencing this error intermittently. Is that correct?

Based on my understanding, if you application is loading the modules loosely (the modules are in XAP files and the Shell does not have a reference to them) then it needs a server to which it can request the modules. As far as I know, even if the application is installed locally it will still try to load the modules through a web request to its server.

  • If you are trying installing the application from the production environment, does the application throw this error? And if you run the application with the computer disconnected from the network?
  • Also, if you are trying installing the application from a development environment please check if there is a local deployment of the application in your machine (for example a running instance if the Visual Studio web server "cassini") when running the installed application and if this affects the error or not.
Regards,

Damian Cherubini
http://blogs.southworks.net/dcherubini
Sep 18, 2013 at 8:20 AM
Thanks for your quick reply!

You've misunderstood: I've only seen this problem when actually deployed in IIS in a production environment. And this is a Silverlight app which cannot run out of browser: we are only running it in-browser, and the failures we see seem to occur when trying to process the AppManifest.xml file in each of our .xap files.

And it occurred just this once, for this one user, and also for that user it was not reproducible.

I've never seen this, or heard colleagues about this, occurring in Visual Studio.

For future reference, here is the actual error we get (multiple times), with PRISM 2.0:
Message: Failed to load type for module ModuleHome. Error was: [Arg_NullReferenceException]
Arguments: 
Debugging resource strings are unavailable. Often the key and arguments provide sufficient information to diagnose the problem. See http://go.microsoft.com/fwlink/?linkid=106663&Version=5.1.20513.00&File=mscorlib.dll&Key=Arg_NullReferenceException.,
StackTrace:    at Microsoft.Practices.Composite.Modularity.ModuleManager.HandleModuleTypeLoadingError(ModuleInfo moduleInfo, Exception exception)
   at Microsoft.Practices.Composite.Modularity.ModuleManager.OnModuleTypeLoaded(ModuleInfo typeLoadedModuleInfo, Exception error)
   at Microsoft.Practices.Composite.Modularity.XapModuleTypeLoader.OnDownloadCompleted(Object o, DownloadCompletedEventArgs e)
   at Microsoft.Practices.Composite.Modularity.FileDownloader.WebClient_OpenReadCompleted(Object sender, OpenReadCompletedEventArgs e)
   at System.Net.WebClient.OnOpenReadCompleted(OpenReadCompletedEventArgs e)
   at System.Net.WebClient.OpenReadOperationCompleted(Object arg)
ClientTime: 9/17/2013 5:05:17 AM,
Type: System.NullReferenceException,
Message: [Arg_NullReferenceException]
Arguments: 
Debugging resource strings are unavailable. Often the key and arguments provide sufficient information to diagnose the problem. See http://go.microsoft.com/fwlink/?linkid=106663&Version=5.1.20513.00&File=mscorlib.dll&Key=Arg_NullReferenceException,
StackTrace:    at Microsoft.Practices.Composite.Modularity.XapModuleTypeLoader.GetParts(Stream stream)
   at Microsoft.Practices.Composite.Modularity.XapModuleTypeLoader.OnDownloadCompleted(Object o, DownloadCompletedEventArgs e)
Also, see the PRISM 2.0 version of XapModuleTypeLoader.cs for (what should be) the corresponding source code.
Developer
Sep 18, 2013 at 7:47 PM
Hi,

Sorry, it seems I got confused at the "installing the application" part. Thanks for the clarification.

Reviewing the XapModuleTypeLoader we came to the same conclusion than you: either there was a problem when trying to read the AppManifest.xml of the XAP files or the stream returned by the WebClient was null. However we don't know what might cause any of those situations, besides maybe, a problem when the web request.
It's also strange that the error appeared only once for one user and could not be reproduced. Unfortunately we are unable to point out the reason behind the error as we cannot reproduce the problem either.

For the record, in which version of Silverlight is your application developed? And which version of Silverlight is installed in the machine where the error appeared?
I would be also useful to know in which browser (and version) the application was running when error appeared, as according to this article the http requests in Silverlight seem to be handled by the hosting browser by default.

Thanks,

Damian Cherubini
http://blogs.southworks.net/dcherubini