ASP.NET - Silverlight XAP FAQ

This FAQ provides answers to questions about Silverlight XAP and ASP.NET. What does XAP mean? Why is XAP important? How does XAP work? How can I create a .xap file in Visual Studio? And, several other questions and answers.

(This information relates to Silverlight 2 Beta 2)

What does XAP mean?

XAP (pronounced ZAP) is the file extension for a Silverlight-based application package (.xap). This file contains the compressed assemblies and resources of a Silverlight 2 application.

What is a .xap file?

A .xap file is a Silverlight-based application package (.xap) that is generated when the Silverlight project is built.

 

Why is XAP important?

Tools, such as Visual Studio 2008 with the Microsoft Silverlight Tools Beta 2 for Visual Studio 2008, allow you to create Silverlight applications that are client based using managed code. You can use managed code, such as C# or Visual Basic, and benefit by using the tools that you are used to working with.

 

How does XAP work?

Once you have created the .xap file (explained below), the Silverlight 2 plug-in downloads the file and runs it in a separate work space.

 

How do I use a .xap file?

A .xap file is used to contain and transfer the assemblies and resources of a managed code application. This managed code application must be run within the Silverlight 2 browser plug-in. Silverlight understands xap files natively and so it can be used as the source directly. 

 

Where can I find the Silverlight 2 Beta 2 plug-in?

https://www.microsoft.com/silverlight/resources/install.aspx?v=2.0

 

What are the Compatible Operating Systems and Browsers for the Silverlight 2 plug-in?

Compatible Operating Systems and Browsers

 

How can I view the contents of a .xap file?

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.

 

What are the files contained in the .xap file?

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

MyPianoV2.dll

 

What is contained in the AppManifest.xaml file?

The AppManifest.xaml file contains the deployment details needed to run the application.

Basic example:

<Deployment xmlns="https://schemas.microsoft.com/client/2007/deployment" xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml" EntryPointAssembly="MyPianoV2" EntryPointType="MyPianoV2.App" RuntimeVersion="2.0.30523.4">

  <Deployment.Parts>

    <AssemblyPart x:Name="MyPianoV2" Source="MyPianoV2.dll" />

  </Deployment.Parts>

</Deployment>

For more information, see Katrien De Graeve blog post titled Silverlight 2: structure of the new .XAP file (Silverlight packaged application).

 

How can I view the contents of the project related assembly?

You can use any dll inspection utility. Here’s an example of the contents of myPianoV2.dll:

dll contents 

 

What tools support creating .xap files?

· Visual Studio 2008 using the Microsoft Silverlight Tools Beta 2 for Visual Studio 2008.

· Expression Blend 2.5 June 2008 Preview

· Chiron.exe – Located in the Tools folder of your Silverlight Tools Beta 2 for Visual Studio 2008 installation. For more information see, Dynamic Languages in Silverlight 2.

 

I’m unable to display the contents of the .xap file when I run the application in a Web page within the browser?

Check the following:

· Make sure you are using the Silverlight 2 Beta 2 plug-in.

· Make sure you have the XAP mime type set for IIS (see below).

· Check to be sure you included your resources, such as graphics, with your Silverlight Application (see below).

· Make sure the .xap file is contained in the ClientBin folder of your Web application.

· Check the Silverlight Tools page for additional troubleshooting details.

 

What is the XAP mime type?

The .xap mime type is:

application/x-silverlight

For more information, see Michael Schwarz blog post and Microsoft Help and Support.

How can I create a .xap file in Visual Studio?

1. Install the following:

· Visual Studio 2008.

· The .NET Framework version 3.5.

· Microsoft Silverlight Tools Beta 2 for Visual Studio 2008.

· Silverlight version 2 Beta 2 plug-in.

 

2. Follow the steps in the following walkthrough to create a .xap file:
Walkthrough: Integrating XAML into an ASP.NET Web Site Using Managed Code

 

What managed programming languages can I use to create a Silverlight 2 application?

C#, Visual Basic

 

What dynamic programming languages can I use to create a Silverlight 2 application?

IronPython, IronRuby, and Managed JScript

For more information, see Programming Silverlight with Dynamic Languages and Dynamic Languages in Silverlight 2.

How do I run the Silverlight 2 application (including the .xap file) with the Silverlight 2 plug-in?

You can use the ASP.NET Silverlight Server Control to reference your .xap file. Specifically, you use the Source property to reference the XAP application package. The Version must be set as well.

 

Code contained in an .aspx file:

<asp:ScriptManager ID="ScriptManager1" runat="server">

</asp:ScriptManager>

<asp:Silverlight runat="server" ID="Silverlight1"

  Height="340"

  Width="320"

  Source="MyPianoV2.xap">

 

Is there an example of a Silverlight 2 Beta 2 .xap application available?

Yes.

Code (C# & VB) that shows how to include a .xap file in a Web page.

Example that shows a running Silverlight 2 Beta 2 application. Note: You will need to install the current runtime plug-in, unless you already have it installed. After installing, close all browser windows and click the Example link.

 

How do I include resources with my Silverlight 2 application?

The example above shows one way to include resources in a Silverlight 2 application. However, Katrien De Graeve has a blog entry titled Different ways for loading images and files in Silverlight 2 applications that explains how to include resources in more detail.

 

What is the XmlXapResolver class?

The XmlXapResolver class is used to resolve resources that are contained in the Silverlight application’s XAP package.

 

What about the XACT Project File Format (.xap)? Is this the same file type as a Silverlight .xap file?

This file type is not related to Silverlight.

The Xbox Audio Creation Tool Project File format (.xap), is read and written by the XACT authoring tool (xact.exe), is utilized by the command-line build environment (xactbld.exe), and contains all of the instructions necessary to generate XACT content. It is a complete description of all XACT wave banks, sound banks, and global settings. For more information see, XACT Project File Format (.xap).

 

Can you point me to additional information?

Yes. Here are a number of links that you may find interesting and helpful.

ASP.NET Controls for Silverlight – ASP.NET Documentation that includes code and running examples.

System.Web.UI.SilverlightControls Namespace – ASP.NET Documentation - managed reference.

Sys.UI.Silverlight (client) Namespace – ASP.NET Documentation – client reference

Silverlight FAQ

Why Silverlight?

Silverlight Resources

Silverlight 2 Beta 2 and Silverlight Streaming

Scott Guthrie’s - Silverlight 2 Beta2 Released