This post will try to shed some light on the Silverlight Application and cater to the following questions…
1. How is a XAP file formed and what are the contents inside it?
2. What would be a good way to maintain the size of an application - Application Library Caching?
3. How to load assemblies on demand?
Create a new Project, called ApplicationStructure using IIS. This is required since later on we will need to use Fiddler to analyze request and response packets.

Add a new Project to this solution… called SilverlightApplication, click Ok

You will get another prompt. Click Ok.

This is how the project structure will look like…

Get rid of MainPage.xaml. Delete it.
Add two new pages called Page1.xaml and Page2.xaml

The following screenshot shows the event that ensures your appropriate page loads when you start your Silverlight application. This is like your Main() method. We'll change this MainPage to Page1, or Page2 as required.

Before you proceed any further, change MainPage to Page1 or Page2, and ensure your Silverlight Application comes up fine.
Page1.xaml looks as follows..
<navigation:Page x:Class="SilverlightApplication.Page1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
d:DesignWidth="640" d:DesignHeight="480"
Title="Page1 Page">
<Grid x:Name="LayoutRoot">
<TextBlock x:Name="txtMessage">This is Page 1</TextBlock>
</Grid>
</navigation:Page>
Page2.xaml is exactly same as Page 1 except that TextBlock reads… Page 2.
Okay, the fun part begins now…
Check your Solution Explorer.

The XAP file that you see here is a ZIP file renamed as XAP.
Notice the following when you open the SilverlightApplication.ZIP. There is an AppManifest.xaml that contains information about DLLs as <AssemblyPart> tag.

Okay, let's add a couple of libraries and see how all this changes.
Install Fiddler, if you haven't done so already.
Add a Silverlight class library called SilverLightClassLibrary1

Add a reference in SilverlightApplication.

Recompile the solution.
Go back to the ClientBin folder and rename the XAP file to Zip. Notice the presence of SilverlightClassLibrary1.dll.

The way this Project is structured, you will find all the Class Libraries going into the same XAP file.
This can lead to two major issues…
1. Bloating up of your XAP file that might take a long time for the end users to download
2. If the application changes in due course, and the SilverlightClassLibrary1.dll doesn't… STILL THE WHOLE XAP will be downloaded. That's a waste of precious bandwidth.
Let's see what can be done to make the experience a bit better. What you are going to do next is what we call Application Library Caching.
Go to the properties of SilverlightClassLibrary1. Sign this assembly with a new Key as you can see below.

Recompile the class library and go to the Debug folder. Create a new file called SilverlightClassLibrary1.extmap.xml

Modify the XML as follows… Don't forget to change the Public key token, or it won't work the way it is expected to!
<?xml version="1.0"?>
<manifest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<assembly>
<name>SilverlightClassLibrary1</name>
<version>1.0.0.0</version>
<publickeytoken>de9bf50b7f561d6e</publickeytoken>
<relpath>SilverlightClassLibrary1.dll</relpath>
<extension downloadUri="SilverlightClassLibrary1.zip" />
</assembly>
</manifest>
One last thing, and you will be all set from configuration perspective. Change the Silverlight application property to
Reduce XAP size.

Done. Now recompile and you will notice that that the folder structure for your web application would change to…

Notice that there is a new Zip file created for you.
Also notice the AppManifest.xaml inside the xap file. You will find Deployment.ExternalParts in addition to Deployment.Parts!

Time to test the application now. Modify SilverlightClassLibary1 -> Class1.cs
namespace SilverlightClassLibrary1
{
public class Class1
{
static public string CurrentTime()
{
return DateTime.Now.ToString();
}
}
}
In the Page.xaml.cs… do the following modification…
public Page1()
{
InitializeComponent();
txtMessage.Text = "Time now is " + SilverlightClassLibrary1.Class1.CurrentTime();
}
Run Fiddler, and browse /ApplicationStructure/SilverlightApplicationTestpage.aspx">http://<YOUR_HOSTNAME>/ApplicationStructure/SilverlightApplicationTestpage.aspx
Notice the status code is 200.
Open a new IE Window and browse your application again…

Notice that instead of Status code 200, you will now get 304… which means "Not Modified". Also notice the body size is 0 KB.
In the next post, we will build on top of this application. You will find out how you can load the assembly later when required, instead of everything being available at one shot when you browse your application. Stay tuned!
Hope this helps,
Rahul
Quote of the day:
Too many people are thinking of security instead of opportunity. They seem more afraid of life than death. - James F. Byrnes