Silverlight: how to make the browser download the updated version of the client?

My Silverlight (4.0) application (hosted on the ASP.NET website) uses 4 projects, all of them use the same assembly file:

[assembly: AssemblyVersion("1.0.*")] 

The version of the currently displayed application is 1.0.3842.38865, but a new one (1.0.3854.42448) has been uploaded to the server recently.

The problem is that the browser does not load the new Silverlight application after it is deployed to the server.

Here is the HTML that is used to render silverlight-html-loader (not sure if this is the correct name):

 <div id="silverlightControlHost" style="height:950px"> <object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%"> <param name="source" value="/ClientBin/VfmElitaSilverlightClientApplication.xap"/> <param name="onError" value="onSilverlightError" /> <param name="background" value="white" /> <param name="initParams" value="adr=squad,team=811,match=3217203" /> <param name="minRuntimeVersion" value="3.0.40624.0" /> <param name="autoUpgrade" value="true" /> <a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=3.0.40624.0" style="text-decoration:none"> <img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style:none"/> </a> </object> <iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe> 

I tried to add a parameter to the "initial" parameter of the object, which contains the time of the last modification of the XAP file:

  <param name="source" value="/ClientBin/VfmElitaSilverlightClientApplication.xap?Ver=2010072243523AM"/> 

This caused an error loading the Silverlight application:

Silverlight Unhandled Error Application Code: 2103 Category: InitializeError Message: Invalid or Invalid Application: Verify Manifest

Could you please advise how to make the browser receive a new application from the server (without manipulating the browser cache, I would like to save the browser cache setting)?

Many thanks!

PS It is necessary to add that the silverlight application works (downloaded and launched) perfectly on my local host without any dances with parameters. Only when I upload it to the website does it not restart with the browser. And adding additional parameters to the path to the xap file does not work on localhost.

+7
silverlight
source share
4 answers

We currently use the following, which receives the latest write time of the .xap file and adds it to the source-param:

 <object ... > <% var source = "ClientBin/App.xap"; string param; if (System.Diagnostics.Debugger.IsAttached) param = string.Format("<param name=\"source\" value=\"{0}\" />", source); else { var path = HttpContext.Current.Server.MapPath(string.Empty) + "\\" + source; var xapCreatedAt = System.IO.File.GetLastWriteTime(path); param = string.Format("<param name=\"source\" value=\"{0}?version={1}\" />", source, xapCreatedAt.ToString("yyyyMMddTHHmmssfff")); } Response.Write(param); %> <param ... 
+4
source share

I'm still testing, but so far it seems that changing AssmeblyFileVersion causes the browser to download the latest xap file. Using Silverlight 4, I tried many other proposed solutions and could not get them to work, or they were not desirable (for example, no caching at all). Now I am increasing the version of the file, and it seems to capture the last xap every time.

 [assembly: AssemblyFileVersion("1.0.0.1234")] 
+4
source share

This should work as expected, possibly due to how you add the parameter. Try removing the Ver= part:

 <param name="source" value="/ClientBin/VfmElitaSilverlightClientApplication.xap?2010072243523AM"/> 

I have used this method in the past and this is the best way to get around any client side caching.

If you want to always update and never cache, you can simply add the current DateTime to the end, which will always be unique. Not sure when you want to do this in a real world scenario, but this is great for testing to ensure you never have a cached version. For example:

 <param name="source" value="/ClientBin/VfmElitaSilverlightClientApplication.xap?<%= DateTime.Now.Ticks.ToString() "/> 

If this does not work, just delete it all together without adding to the end and see if it boots. I have the feeling that the error is something else as it does not relate to the location of the xap file.

+2
source share

The right approach to managing your browser's cache is to tell him what you expect from him using the approved HTTP response headers sent by the server.

In IIS Manager, specify that the contents of the ClientBin folder should immediately expire.

Please note that this does not mean that Xap wil is loaded for every request, just so that the browser should check that its cached copy has been updated.

+1
source share

All Articles