Lars Holm Jensen's Code Blog

Just another WordPress codeblog on C#, Silverlight and all things .NET

Archive for the ‘xap’ tag

Avoid incorrect Silverlight XAP file caching

with 47 comments

The code below appends the last-write filedate of the Silverlight Application XAP file to the path in the source parametre of the Silverlight object tag.
This will ensure that poorly constructed caching functionality of webbrowsers and proxy servers doesn’t incorrectly use old, wrong builds of the XAP file.
However it will still allow these caches to work. Furthermore a check is performed to avoid XAP file path alteration during debugging, this is to allow debugging tools such as Silverlight Spy to continue functioning.

<object id="Xaml1" data="data:application/x-silverlight-2," type="application/x-silverlight-2"

width="100%" height="100%">

<%––<param name="source" value="ClientBin/SilverlightApp.xap"/>––%>


string orgSourceValue = @"ClientBin/SilverlightApp.xap";

string param;

if (System.Diagnostics.Debugger.IsAttached)

param = "<param name=\"source\" value=\"" + orgSourceValue + "\" />";



string xappath = HttpContext.Current.Server.MapPath(@"") + @"\" + orgSourceValue;

DateTime xapCreationDate = System.IO.File.GetLastWriteTime(xappath);

param = "<param name=\"source\" value=\"" + orgSourceValue + "?ignore="

+ xapCreationDate.ToString() + "\" />";




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

Written by larsholm

February 1st, 2010 at 8:06 pm