Click here to Skip to main content
15,868,016 members
Articles / Web Development

Steps to Discuss Application Library Caching in Silverlight 4

Rate me:
Please Sign up or sign in to vote.
4.93/5 (23 votes)
14 Mar 2011CPOL5 min read 74.9K   20   42
Steps to Discuss Application Library Caching in Silverlight 4

Introduction

Sometimes, your Silverlight application becomes too large and creates a bigger XAP file. This causes an issue while loading your XAP file for the first time as it increases the loading time for downloading the XAP. So, what will you do in this case? There is one answer: split your application in multiple projects which will create multiple XAPs and then use On Demand downloading feature.

Absolutely right, but you may sometimes include 3rd party assembly references. In such a case, storing them in a separate XAP and writing the code for downloading them on demand will be very hectic. So, what's the easy process? In this article, we will learn the same. Read to know more and provide your feedback in case you need more information.

Assembly caching is not a new thing in Silverlight 4. It was present since Silverlight 3. Today, I got a chance to look into it and thought if sharing the same with in-depth details.

So, what is Application library caching? We all know about the on demand download of XAP. To do this, we need to write code for downloading the external XAP files using WebClient. Application Library caching does the similar thing for you very easily. Suppose, if you have a bigger application and used huge 3rd party libraries, this easy step will help you make a separate zip file with them which can be downloaded on demand without writing any additional code.

Many people don't know about it and hence let's start describing that here.

Step 1 - Digging Inside XAP

First of all, we will create a small Silverlight Application project. To do this, open your Visual Studio and create that.

image

Once you are done creating the project, in Solution Explorer you will see that it has some default references to some assembly files. Once you build the project, it will create a .XAP file for you. Here is a screenshot of the same:

image

You can see that it creates the XAP file in the client bin directory. It creates a single XAP irrespective of number of assembly files referenced to that project and unnecessarily increases the size of XAP file whether it requires those or not.

To see the contents inside the XAP, go to the ClientBin folder. There, you will find the XAP output of your Silverlight application.

image

As you all know, all the XAP files are nothing but a ZIP file, hence you can easily convert it to a Zip file by renaming its extension.

image

Open the ZIP file. Inside that, you will find "AppManifest.xaml" (which stores the referenced Assembly information), DLL output of your project and all other referenced assemblies. If you add more 3rd party assembly reference in your solution, this list will increase.

image

To know details of that, open the AppManifest.xaml file in a text editor. Have a look into the below screenshot:

image

You will notice that it has all the referenced DLL information as Assembly part, entry point and required runtime version. Assembly parts tell to load the referred assembly directly from the XAP.

Step 2 - Working with More Assemblies

Just visualize what we demonstrated in the first step. Now, we will add some additional DLL reference in our project. To do that, right click on your project and click "Add Reference'. Now from the add reference dialog, select some 3rd party DLLs and include them in your project.

For the demonstration, we will add some theming DLLs in our solution. To do this, search for "theme" and you will see a list of theming DLLs in the add reference dialog. Chose some of them and add into the project.

image

Once you add them, you will notice that the selected assemblies are now part of your project (see the figure below):

image

Now, build your solution and open the new XAP file (rename it to a ZIP). You will see that all the new referenced DLLs are now part of your XAP. See the below screenshot, which will give you better information:

image

Let us open the "AppManifest.xaml" and see what it contains now. Wow, it contains all those additional DLL entries as AssemblyPart and tells to load them from the XAP itself.

image

This actually increases the XAP size and makes your application little bulky. Thus increases initial loading time of your application.

Step 3 - Using Application Library Caching

To overcome this, let us change the setting of our project to use the Application library caching feature now. Go to your project properties panel. In the Silverlight tab, you will find a checkbox called "Reduce XAP size by using application library caching". Check this as shown below:

image

Now build your project once again and you will see that it will create as many .ZIP files as the count of external assemblies as shown below. You will also notice that it creates a single zip for a single referred DLL assembly.

image

Let us go into the deep to lookout for the Application Manifest. Go to the output directory "ClientBin". You will see a single XAP file with a number of ZIP files shown below:

image

Each ZIP contains a single DLL file here. Rename and open the XAP file. Open the AppManifest.xaml from the XAP.

image

Here, you will notice a single AssemblyPart pointing to your original project output and rest of the DLL references are now moved to ExternalParts. They are now pointing to the Zip files instead of the actual DLLs.

Now, when you run your application, it will only download the XAP file which contains only the main resources. Rest of the DLL ZIP will be downloaded on demand whenever required by your application.

Hope this information will help you to understand the library caching feature of Silverlight and give you the chance to use it in your application. Let me know in case you need further information on that.

History

  • 14th March, 2011: Initial version

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Technical Lead
India India

Kunal Chowdhury is a former Microsoft "Windows Platform Development" MVP (Most Valuable Professional, 2010 - 2018), a Codeproject Mentor, Speaker in various Microsoft events, Author, passionate Blogger and a Senior Technical Lead by profession.

He is currently working in an MNC located in India. He has a very good skill over XAML, C#, Silverlight, Windows Phone, WPF and Windows app development. He posts his findings, articles, tutorials in his technical blog (www.kunal-chowdhury.com) and CodeProject.


Books authored:


Connect with Kunal on:





Comments and Discussions

 
GeneralMy vote of 1 Pin
Member 108796242-Jul-14 8:31
Member 108796242-Jul-14 8:31 
Questionfacing issue with the Application Library Caching Pin
anildcsc7-Dec-11 2:38
anildcsc7-Dec-11 2:38 
AnswerRe: facing issue with the Application Library Caching Pin
Kunal Chowdhury «IN»7-Dec-11 17:00
professionalKunal Chowdhury «IN»7-Dec-11 17:00 
GeneralMy vote of 5 Pin
JugalPanchal1-Jul-11 3:28
JugalPanchal1-Jul-11 3:28 
GeneralRe: My vote of 5 Pin
Kunal Chowdhury «IN»31-Jul-11 7:42
professionalKunal Chowdhury «IN»31-Jul-11 7:42 
GeneralMy vote of 5 Pin
Anil_Saran27-Mar-11 17:55
Anil_Saran27-Mar-11 17:55 
GeneralRe: My vote of 5 Pin
Kunal Chowdhury «IN»18-Apr-11 5:08
professionalKunal Chowdhury «IN»18-Apr-11 5:08 
GeneralMy vote of 5 Pin
TweakBird23-Mar-11 8:24
TweakBird23-Mar-11 8:24 
GeneralRe: My vote of 5 Pin
Kunal Chowdhury «IN»23-Mar-11 16:19
professionalKunal Chowdhury «IN»23-Mar-11 16:19 
GeneralMy Vote of 5 Pin
RaviRanjanKr19-Mar-11 20:00
professionalRaviRanjanKr19-Mar-11 20:00 
GeneralRe: My Vote of 5 Pin
Kunal Chowdhury «IN»19-Mar-11 20:09
professionalKunal Chowdhury «IN»19-Mar-11 20:09 
QuestionWhat do you mean by Pin
Sacha Barber17-Mar-11 7:08
Sacha Barber17-Mar-11 7:08 
AnswerRe: What do you mean by Pin
Kunal Chowdhury «IN»17-Mar-11 22:23
professionalKunal Chowdhury «IN»17-Mar-11 22:23 
GeneralRe: What do you mean by Pin
Sacha Barber17-Mar-11 22:34
Sacha Barber17-Mar-11 22:34 
GeneralMy vote of 5 Pin
JF201516-Mar-11 20:01
JF201516-Mar-11 20:01 
GeneralRe: My vote of 5 Pin
Kunal Chowdhury «IN»17-Mar-11 5:18
professionalKunal Chowdhury «IN»17-Mar-11 5:18 
GeneralImages Pin
#realJSOP16-Mar-11 8:01
mve#realJSOP16-Mar-11 8:01 
GeneralRe: Images Pin
Kunal Chowdhury «IN»16-Mar-11 8:25
professionalKunal Chowdhury «IN»16-Mar-11 8:25 
GeneralExcellent! Pin
Nish Nishant16-Mar-11 3:11
sitebuilderNish Nishant16-Mar-11 3:11 
GeneralRe: Excellent! Pin
Kunal Chowdhury «IN»16-Mar-11 6:14
professionalKunal Chowdhury «IN»16-Mar-11 6:14 
GeneralMy vote of 5 Pin
Nish Nishant16-Mar-11 3:11
sitebuilderNish Nishant16-Mar-11 3:11 
GeneralRe: My vote of 5 Pin
Kunal Chowdhury «IN»16-Mar-11 6:13
professionalKunal Chowdhury «IN»16-Mar-11 6:13 
GeneralRe: My vote of 5 Pin
Nish Nishant16-Mar-11 6:25
sitebuilderNish Nishant16-Mar-11 6:25 
GeneralRe: My vote of 5 Pin
Kunal Chowdhury «IN»16-Mar-11 6:38
professionalKunal Chowdhury «IN»16-Mar-11 6:38 
GeneralRe: My vote of 5 Pin
Nish Nishant16-Mar-11 6:41
sitebuilderNish Nishant16-Mar-11 6:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.