Sunday, November 20, 2011

What is Application Library Caching

Most of the time including this extra assembly in your XAP file would be fine. There is an alternative though. You can separated the Microsoft.Maps.MapControl assembly out and have the client’s browser cache it locally. This is called “Application Library Caching”. If the client already has a cached copy of the assembly it does not need to be downloaded again. This would obviously decrease the amount of content that needs to be downloaded for the application to run. To configure the Silverlight project to use library caching you right-click on the project in Solution Explorer and choose the “Properties” option. This will open the properties tab for the project and then you check the box labeled “Reduce XAP size by using application library caching”, as shown in the following screen capture:

ClientBin folder is used to place the .XAP file of Silverlight application. You can keep this anywhere in your web application but this is the default that is used by the Silverlight.
The .XAP mime type is: application/x-silverlight

AppManifest.xaml file?

The AppManifest.xml file defines the assemblies that get deployed in the client application. This file is automatically updated when compiling your application.
Basic example:

<deployment entrypointassembly="MySimpleSilverlight" entrypointtype="MySimpleSilverlight.App" runtimeversion="3.0.40624.0" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns="http://schemas.microsoft.com/client/2007/deployment">
<deployment.parts>
<assemblypart source=" MySimpleSilverlight.dll" x:name="MySimpleSilverlight">
<assemblypart source="Microsoft.Maps.MapControl.Common.dll" x:name="Microsoft.Maps.MapControl.Common">
<assemblypart source="Microsoft.Maps.MapControl.dll" x:name="Microsoft.Maps.MapControl">
</assemblypart></assemblypart></assemblypart></deployment.parts>
</deployment>
Based on the settings of a referenced assembly it is added to the Application manifest. For example, if you have an assembly that you are referencing in your application but do not wish to have it included into the. XAP file you can choose to set “Copy Local” to false. See the image below:

In this example I’m referencing the Microsoft.Maps.MapControl.Common assembly and chose not to have a local copied deployed with the .XAP. I’ll then need to add “on demand download of the assembly” when accessing it in my code.
This can be useful to have only your base assembly deployed and have an on demand download of subsequent assemblies on the fly so that your initial download time is minimal. When only a part of your application uses a specific assembly you may want to use this mechanism.

What is XAP File?

A XAP file (pronounced "zap") is basically a compressed output file for the Silverlight application containing Silverlight solution components such as the compiled XAML and code-behind, an application manifest and possibly one or more assemblies delivering Silverlight controls.
When a Silverlight project is built in Visual Studio all of the files, XAML and .NET code, are compiled into a single DLL.  This DLL file is then compressed into a zip file that gets named with a .XAP extension rather than the traditional .ZIP.  In addition to XAML and code files, graphics and media files are compiled by default into the DLL assembly as well.
".XAP" files use the standard .zip compression algorithm to minimize client download size. A "hello world" .NET Silverlight application (built using VB or C#) is about 5KB in size. The size of the file depends on the XAML files, assemblies used in Silverlight project.

To view the contents of a .XAP file you can rename the extension of the .XAP file to .ZIP. Then view the .ZIP file using any standard .ZIP utility.


A basic XAP file will have an assembly related to specific code for the application, an application manifest file and any additional assemblies need to run the application. At a minimum, two files are needed, the application manifest file and the application assembly.
For example:
  • AppManifest.xaml
  • Demo1.dll
Here Microsoft.Maps.MapControl.Common.dll and Microsoft.Maps.MapControl.dll are two external dlls used in the Silverlight application to show the Bing Map.External resources like images or other types of files can also be added to the .XAP file if you do embed them into your client DLL .