0

Up until a few minutes ago, my Silverlight app was hitting breakpoints beautifully in Firefox. However, not only does it now show that the breakpoint won't be hit (outline instead of solid breakpoint), based on some Debug.WriteLine statements, I can see that an older version of my code is being executed.

What's going on here? How can I troubleshoot and fix this problem? Is this a known issue?

I also had Chrome working like this in the past, but then it, too, mysteriously stopped hitting breakpoints. (I never used attach-to-process to manually attach.)

ashes999
  • 9,925
  • 16
  • 73
  • 124
  • I've had to go back to IE for debugging Silverlight. It's the only browser that consistently hits breakpoints. It's a pain as you have to make it your default browser for the duration. – ChrisF Aug 17 '11 at 19:21
  • You should add this as an answer. It might well be the accepted answer. Except that IE9 doesn't hit breakpoints for me :) – ashes999 Aug 17 '11 at 19:41
  • In that case it might not be the answer then (hence the comment). Are you using the VS web server or IIS Express? – ChrisF Aug 17 '11 at 19:41

2 Answers2

3

It seems like your browser is holding on to a cached version of your XAP file and using that instead of your most recent compiled XAP. I know this sounds trivial but have you tried clearing your browser history?

avanek
  • 1,649
  • 12
  • 20
  • That seems to be it. Why does this happen intermittently though? – ashes999 Aug 17 '11 at 19:40
  • I honestly don't know the technical details behind Firefox's caching mechanisms but I imagine it uses a different technique than IE when it comes to Silverlight apps. You can take a look at this SO post for some solutions people have for [preventing this caching issue](http://stackoverflow.com/questions/307709/how-do-you-force-firefox-to-not-cache-or-re-download-a-silverlight-xap-file) – avanek Aug 17 '11 at 19:57
  • I stand corrected. Clearing the cache did NOT fix the problem. – ashes999 Aug 17 '11 at 20:29
0

We had an issue with our deployed application whereby the client wasn't downloading the latest version of the xap files despite them being updated on the server and clearly being different, both in terms of size and date modified. We don't appear to be getting this on our development machines though.

Something similar could be going on here.

We solved our problem by appending ?[xap file date] to the reference of all xap files. This was in both the xspx page for the main xap file and in the database for all the Prism references. This dummy query string appears to be enough to fool the browser into treating the xap file as different and so downloading the updated version.

For the xap file referenced in the aspx page you need to follow the steps outlined in this blog post. The main part is this code:

<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
   <%
       string strSourceFile = @"ClientBin/SilverlightApplication2.xap";
       string param;    
       if (System.Diagnostics.Debugger.IsAttached)
           //Debugger Attached - Refresh the XAP file.
           param = "<param name=\"source\" value=\"" + strSourceFile + "?" + DateTime.Now.Ticks + "\" />";
       else
       {
           //Production Mode 
           param = "<param name=\"source\" value=\"" + strSourceFile + "\" />";
       }
       Response.Write(param);
    %> 
     <param name="onError" value="onSilverlightError" />
     <param name="background" value="white" />
     <param name="minRuntimeVersion" value="4.0.50826.0" />
     <param name="autoUpgrade" value="true" />
     <a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.50826.0" style="text-decoration:none">
          <img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight" style="border-style:none"/>
     </a>
</object>

What this does is find the current time stamp of the xap file and append it. The generated code will look something like this:

<param name="source" value="ClientBin/SilverlightApplication2.xap??634299001187160148">

This makes the xap file reference unique for each time it updates.

ChrisF
  • 134,786
  • 31
  • 255
  • 325