Fix for Could not download the Silverlight application error

by APIJunkie 2. August 2008 10:08

If you receive the following error:  Could not download the Silverlight application. Check web server settings.

The problem might be the fact that the .xap mime type is not registered on the IIS server you are using.

If you have control over your server then you can just register the missing mime type.

If you are not that lucky you might need to find a workaround like the one below.

The idea is based on an older solution for Silverlight 1.0 and xaml files.

Since the problem is do to the fact that xap is not a registered mime type, we can cheat a little by creating an http handler that will handle requests for xap files.

The http handler will deliver the content of the xap file using a mime type that is known to the server. 

Since a xap file is actually a zip file we can use that mime type as the delivery content type.


Create a new class file called HttpXapHandler.cs.

Copy the following code to the file and add the file to your App_Code directory.

/// <summary>

/// HttpXapHandler class - handle requests to xap file through a back door nick named x-zip-compressed.

/// </summary>

public class HttpXapHandler : IHttpHandler


public void ProcessRequest(HttpContext context)


// get file name from request query string

string fileName = context.Request["fileName"];

// check if the file is valid -> its up to you to validate in a way that makes sense to you...

if (!validateFile(fileName))


"<br>Bad file request<br>");



// set mime type to zip file because a xap file is actually a zip file

context.Response.ContentType = "application/x-zip-compressed";




// naive test for valid xap file -> just test if the file requested is actualy a .xap file

public bool validateFile(string fileName)


fileName = fileName.ToUpper();

if ((fileName.Length > 4) &&(fileName.Substring(fileName.Length - 4).CompareTo(".XAP") == 0)


return true;


return false;


public bool IsReusable




return false;




// EOF HttpXapHandler

After you created the http handler add the following line to your web.config file inside the httpHandlers section(note the bold part):

<httpHandlers> <add verb="*" path="GetXapFile.ashx" type="HttpXapHandler" validate="false"/>


Now that we have an http xap handler our web site should be able to accept requests like this:

To actually use this inside a web page take a look at the next example.

Usage example:

To access the .xap files in your web pages you will need to replace each occurrence of the source=[xap file name] with source=getXapFile.ashx?fileName=[xap file name].

In your html page this will look something like the following (note the bold part):

<div id="silverlightControlHost">

<object data="data:application/x-silverlight," type="application/x-silverlight-2-b2" width="100%" height="100%">

<param name="source" value="getXapFile.ashx?fileName=mySilverlight2file.xap"/>

<param name="onerror" value="onSilverlightError" />

<param name="background" value="white" />


<a href="" style="text-decoration: none;">

<img src="" alt="Get Microsoft Silverlight" style="border-style: none"/>



<iframe style='visibility:hidden;height:0;width:0;border:0px'></iframe>


good luck!


IIS | Silverlight | Troubleshoot


8/2/2008 10:23:05 AM #


Trackback from

Fix for Could not download the Silverlight application error

8/9/2008 10:27:22 AM #


Trackback from Community Blogs

Silverlight Cream for August 09, 2008 -- #341

Community Blogs

9/2/2008 10:38:31 PM #


Trackback from Silverlight for dummies

My Silverlight application is not supported by my server

Silverlight for dummies

Comments are closed

About the author

Name of author

I was first wounded by x86 assembly, recovered and moved on to C. Following a long addiction to C++ and a short stint at rehab I decided to switch to a healthier addiction so I am now happily sniffing .NET and getting hooked on Silverlight.

I am mainly here to ramble about coding, various API’s, Junkies(me especially) and everything else that happens between coders and their significant other.

  James Bacon