There is not much documentation out there that explains the best ways to work with Xaml Browser Applications (XBAPs). At my job, I recently inherited an application that is deployed both to the desktop and as XBAP, so I decided to study up on the topic. To my dismay, there is hardly anything out there beyond the basics. I intend on helping to fill that gap by blogging about XBAP-related tips and tricks that I learn along the way.
In this post, I share three tips that have helped me out a lot already.
XBAP Tip 1
When in doubt, clear it out. The XBAP applications are stored in a local cache on the client. Sometimes this is great, sometimes it can be a problem. If you make some changes in your code/XAML that you just know should be appearing when you run the app, but don’t, then it’s time to clean your cache. You can do so by running this:
rundll32 %windir%\system32\dfshim.dll CleanOnlineAppCache
I put that command in the Run dialog and just run it whenever I feel that the XBAP Gods are not smiling down upon me.
XBAP Tip 2
Unfortunately Snoop does not work with XBAPs. But…Mole does!! In order to molenate an XBAP you need to perform one extra step, that is not necessary for a normal WPF app. If you try to open the Mole debugger visualizer for an XBAP with the default security settings, you will receive this error from Visual Studio:
In case that image does not show up for you, it says: “The application you are debugging has insufficient privileges to allow the use of custom visualizers. Please see the documentation for the list of required privileges.”
In order to give an XBAP sufficient privileges to be molenated, you must open the project’s properties, go to the Security tab, and select the “This is a full trust application” option. This is seen below:
XBAP Tip 3
This tip is related to tip 2. Since you probably do not want to deploy your XBAP as a full trust application, you need to remember to revert the project setting back to “This is a partial trust application” at some point. If you want to be 100% certain that you’ve done so, simply call the following method from your main Page’s constructor (or wherever makes sense for you):
void VerifyPartialTrust() { try { new DropShadowBitmapEffect(); Trace.Fail("Warning: Project set to Full Trust!"); } catch { } }
Since a partial trust XBAP cannot touch bitmap effects, such as DropShadowBitmapEffect, creating an instance of one will throw an exception. If you can create an instance without an exception being thrown, the code above shows a warning message that you can’t miss!
This is also very handy when doing XBAP / WPF App work
http://scorbs.com/2006/06/04/vs-template-flexible-application/
Its a VS addin which allows you to target Debug/Build/XBAP Debug/XBAP Release
Good call! Thanks Sacha
Nice post.
Guess old Moles never die!!
😀 Mole is a crucial piece of my dev toolbox. I’m so glad we made it!!
In regards to Tip 1, I’ve noticed on some client deployments that simply trying to clear the cache via the command (or mage -cc) doesn’t seem to actually remove the previous installed app, and the clickonce deployed app will get into an odd state. In these case, deleting the folder C:\Documents and Settings\$user\Local Settings\Apps\2.0 will resolve it, and reduce the amount of hair pulling needed.
Thanks David. That’s good to know!
Thanks for the post.