.net – Silverlight: how to force browser to download updated client version

asp.netnetsilverlight

My Silverlight (4.0) app (hosted by ASP.NET website) uses 4 projects, they all use one file with assembly version:

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

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

The problem is that browser doesn't load new Silverlight application after it's deployment to server.

Here is a HTML-code that is used for "rendering" of silverlight-html-loader (not sure if it a 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've tried to add a parameter to the "source" parameter of the object that contains time of last XAP-file modification:

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

That caused an error of Silverlight application loading:

Unhandled Error in Silverlight
Application Code: 2103 Category:
InitializeError Message:
Invalid or malformed application:
Check manifest

Could you please advise how to force browser to get new application from server (without browser cache manipulating, I would like to keep browser caching option)?

Thank you very much!

P.S. It is necessary to add that silverlight application works (uploaded and launched) fine on my localhost without any dancing with parameters. Only when I upload it to web site – it is not reloaded by browser. And adding additional parameters to the xap-file path – doesn't work on localhost.

Best Answer

What we use currently is the following which gets the last write time of the .xap-file and appends 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 ...
Related Topic