Saturday, 7 March 2009

Xap != Zip (Silverlight gets confused)

After I had tested (or thought I'd tested) and uploaded the Searcharoo version 7 CodeProject article, I deployed 'example code' to, including the Silverlight UI. I was shocked and annoyed when it failed to run!

It's worth noting that my hosting provider doesn't server .XAP files by default, so of course I had just renamed the Silverlightaroo.XAP to Silverlightaroo.ZIP, updated the reference in the HTML and expected it would work (like Tim says it should).

BUT all I got was
Microsoft JScript runtime error: Unhandled Error in Silverlight 2 Application This operation is not supported for a relative URI. at System.Uri.get_Host()
string host = Application.Current.Host.Source.Host;
I was confused why this would work fine with .XAP but not with .ZIP... these are the three scenarios I tried to get it working:

1. <param name="source" value="Silverlightaroo.xap" />

This works fine on my local PC, but breaks on my hosting provider because the XAP file returns a 404 so the Silverlight application never loads.

When it works locally, you can see that the Application.Current.Host.Source properties are all populated correctly:

2. <param name="source" value="" />

Because option #1 doesn't work on my server, I simply renamed .XAP→.ZIP and updated the HTML - but this causes the error shown above. When I debug the Silverlight, the Application.Current.Host.Source properties all throw exceptions:

3. <param name="source" value="http://localhost:3359/" />

The solution was to use the FULL path to the Silverlight .ZIP file, and once again the Application.Current.Host.Source properties are populated:

This is not ideal, because now I have to remember to change the HTML OBJECT tag "source" PARAM between development/test and production servers - but at least it works! You can see the page in action.

Is it just me - or is this a bug?


  1. In the zip file, you also did not include the xml files "z_searcharoo-cache.xml" and "z_searcharoo.xml", how do get these coz site wont run without them

  2. What site do you mean? The files you mention are intended for the server-side code: the Silverlight application doesn't access them directly.

    If you are implementing Searcharoo for another site, you generate those files based on your own site contents.

  3. Can you explain how do you generate the "z_searcharoo-cache.xml" file? Thanks.

  4. The cache is generated by the indexer running. The file name and location are controlled by .config file options/entries. More info in the articles at

  5. To all who are having issues with these files,

    Make sure to compile the core libraries. Run the indexer after modifying app.config appropriately. The indexer will generate these files which you can add back to the WebAppCatalogResource project. Build the test web application afterwards.