22

I developed a XAML browser application (XBAP) that is embedded within an ASP.NET web page. I am having a problem getting the latest version of the XBAP to update on the client computer. During development, I have had to use the Mage.exe tool to clear out the application cache so that my changes will be seen when running on my local computer. Besides executing Mage.exe -cc in the command line, I have also found rundll32 dfshim CleanOnlineAppCache to work just as well.

However, I do not want to ask customers to run any commands in the command line. What will I have to do to make the XBAP automatically update on the client computer? Instead of the updated XBAP refreshing on the client computer, the previous version of the XBAP continues to run.

Update

I created a bounty on this question because I have the same issue. From what I read online, XBAPs are supposed to compare the cached version # with the version # of the one on the webserver, and download the new version if it's different. I've verified that my version numbers are different, but the cached copy is still the one that is running when I launch the XBAP.

The cached copy also comes if I launch the XBAP outside of the asp.net page, although I do get the new version if I change the url parameters.

Update #2

I've discovered that the XBAP does automatically update on XP 32-bit machines, but not on my Windows 7 64-bit machine.

Rachel
  • 122,023
  • 59
  • 287
  • 465
Alcy
  • 221
  • 2
  • 4

7 Answers7

2

You could try something like this, although I use it in XAPs not XBAPs it might work for you too:

(snippet follows)

public partial class App : Application
{
    /// <summary>
    /// Creates a new <see cref="App"/> instance.
    /// </summary>
    public App()
    {
        Application.Current.CheckAndDownloadUpdateAsync();
        // rest of code

EDIT

Was gonna suggest incrementing version number between publishes but it seems that's already been taken care of. Does this behavior happen on all browsers ? Might be some IE-specific bug/oddity (i've seen plenty of IE-only misbehaviors... wouldn't surprise me)

Alex
  • 22,093
  • 3
  • 36
  • 68
  • 1
    That method does not seem to exist in an XBAP – Rachel Nov 03 '11 at 15:50
  • I tested with IE, FireFox, and Chrome, and they all fail to download the new version. – Rachel Nov 04 '11 at 18:30
  • 1
    [CheckAndDownloadUpdateAsync](http://msdn.microsoft.com/en-us/library/system.windows.application.checkanddownloadupdateasync(v=vs.95).aspx) seems to be a Silverlight-only function, not WPF/XBAP. – John C Feb 13 '12 at 19:04
  • for WPF; replace the above code with **new System.Deployment.Application.DeploymentServiceCom().CleanOnlineAppCache();** - courtesy of http://stackoverflow.com/questions/11774838/xbap-clear-cache-from-application – else Feb 25 '16 at 12:50
2

Years ago, we had this problem with an ordinary website. It kept haunting us, and in the end, we ended up changing the url prefix for each new version. The very first page was never cached, and forwarded to the updated url.

Its a workaround, I know, but a very reliable one.

0

I deploy my Xbap by simply copying filest to ClientBin directory in my web project. I display it in iframe. To make application "refresh" version I have to change "Publish Version" in Xbap project before build. Project Properties -> Publish -> Publish Version.

This changes version in xbap and manifest file forcing clients to download newest version.

Grzegorz W
  • 3,347
  • 1
  • 17
  • 20
0

without the correct cache headers your browser may be preventing downloading the xbap.

clear cache to see if this fixes it.

alternatively use:

<%string versionInfo = typeof (AVSTX.POS.WebMvc.Controllers.HomeController).Assembly.GetName().Version.ToString(); %>
<param name="source" value="<%=ResolveUrl("~/ClientBin/AVSTX.POS.WebRia.xap?version=" + versionInfo) %>"/>

to create a new url which the browser cannot cache at this point. It is based on inspecting the host assembly version so make sure to increment [assembly: AssemblyVersion("3.4.9.0")] [assembly: AssemblyFileVersion("3.4.9.0")]

this solution won't solve the dynamic modules you may download in the future. you will need to fix the actual cache headers if this is your problem.

edit 1: code to disable browser caching

    //http://stackoverflow.com/questions/1160105/asp-net-mvc-disable-browser-cache
//http://developer.yahoo.com/performance/rules.html#expires
//http://ray.jez.net/prevent-client-side-caching-with-httpmodules/
//http://stackoverflow.com/questions/2281919/expiry-silverlight-xap-file-from-browser-cache-programmatically
public class XapFileHttpModule : IHttpModule
{
    #region IHttpModule Members

    public void Init(HttpApplication context)
    {
        context.BeginRequest += context_BeginRequest;
    }

    public void Dispose()
    {
    }

    private void context_BeginRequest(Object source, EventArgs e) 
    {
        HttpApplication application = (HttpApplication)source;
        HttpContext context = application.Context;

        if(context.Request.FilePath.Contains(".xap"))
        {
            context.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));
            context.Response.Cache.SetValidUntilExpires(false);
            context.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
            context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
            context.Response.Cache.SetNoStore(); 
        }
    }

    #endregion
}
Leblanc Meneses
  • 2,922
  • 1
  • 21
  • 25
  • Won't this re-download the app anytime it gets run? The whole point of caching it is so it doesn't re-download, which I like because it makes the startup time faster. – Rachel Nov 08 '11 at 13:08
  • only on new releases will it re-download. The url created is based on the host website AssemblyVersion (i keep it the same as the app using linked files). So caching still works. If you dynamically download new assemblies you may still have the same caching problems that can be resolved with http://compositewpf.codeplex.com/discussions/240811?ProjectName=compositewpf – Leblanc Meneses Nov 08 '11 at 23:29
  • Do you know how to implement this in an XBAP? (or if it is even possible?) The code and link you posted both look like they're for Silverlight only. – Rachel Nov 09 '11 at 12:56
  • the link is not specific to sl, it is more specific to the prism infrastructure and how you manage assemblies on demand. I actually have this in my backlog to implement but haven't had time. I currently have caching disabled permanently until i build the loader. I rather have a slow download than a broken app. I've added the httpmodule i built to disable caching for .xap .. you can add your extensions for files being cached and not updated. (added to the original comment) – Leblanc Meneses Nov 09 '11 at 15:47
  • I am still unclear how I would implement this in an XBAP, which is a WPF application that runs in a Web Browser, not a Silverlight application. I don't use MVC, or PRISM (other than the `NotificationObject` and `EventAggregator`), and `.xap` is the the extension for Silverlight. My bounty ends in about half an hour, and I still don't have an answer about how I can fix this issue so I am letting it expire. If your solution does actually work in XBAPs then I'll add a 2nd bounty and give you the points. – Rachel Nov 10 '11 at 13:07
0

You can use ClickOnce to deploy your application. If you want to force user to update just set minimum required version for the application (it's in Application Updates dialog box).

Ekk
  • 5,419
  • 16
  • 27
  • I want to keep the app embedded in the website, and ClickOnce will make it run outside the site. Also, the load time of ClickOnce apps is more than I prefer. – Rachel Nov 08 '11 at 13:06
0

Application caching is done via manifest files caching, when manifests signatures changes, runtime will upgrade the local files (moreover it just upgrade the changed files). Just sure that you has the right headers sent on HTTP responses. Sometimes dynamic pages cache settings or hosting providers global settings interfere. For me, it always works out of the box.

0

ClickOnce worked for me like a charm. Also make sure that you're versioning your XBAP properly.

grzegorz_p
  • 454
  • 1
  • 4
  • 14