On Saturday went hiking to Mount Si, one of the quintessential Seattle hikes.
It was a beautiful day, with a clear view of Mount Rainer from the top.

karen corby’s fabulous blog
On Saturday went hiking to Mount Si, one of the quintessential Seattle hikes.
It was a beautiful day, with a clear view of Mount Rainer from the top.

If your XBAP has some “heft” to it (large resource files, large assemblies, etc), it may make sense to architect your app to use ClickOnce’s OnDemand APIs.
OnDemand APIs enable developers to delay download parts of the application. This can result in a friendlier end-user UX. Note: OnDemand files can be traditional resource files (e.g. images, xml files, etc) or assemblies.
Architecture Tips & Tricks
Got satellite assemblies or large resource files? Slim down your primary EXE to the bare minimum needed to start the app. Then, when the XBAP is launched, only the application manifest, deployment manifest, and primary EXE will be downloaded. As the user navigates around the xbap, you can use a second thread to download other files/assemblies silently in the background or show app-specific progress UI.
The Sample
I’ve created a sample XBAP that does just this:
The major implementation steps are:
Try it out the xbap (RC 1). Get the code here.
Note: OnDemand APIs should only be called when applications are actually deployed using ClickOnce, not during F5 debug.
Pretty Illustrations
Step 1 above: Setting resources files as Content

Step 3 above: Setting resources files as Content

More Resources
When relying on resources living on a server, you can increase client app perf & decrease network traffic by storing local versions. When trying to build a sandboxed XBAP, however, you cannot create your own local cache store in the file system beyond the space available in isolated storage (512KB).
Fortunately, WPF resource loading uses System.NET’s HttpWebRequest and its “Default” caching policy. In addition, depending on your resources’ sizes and your scenario, it may make sense to use a non-default caching policy when issuing your own HttpWebRequest.
This post aims to give you a little bit of caching context, an overview of your caching options and some sample code.
Understanding the HTTP Cache
How long is something good for?
This answer is determined through a combination of server & client settings.
The server sets the HTTP Response Header “Expires” to indicate the time after which a resource is considered stale. A stale cache entry may not normally be retrieved unless it is first validated with the origin server as being the current version. In addition, the server may specifiy certain cache directives in the header. These include “no-cache,” “max-age,” and “must-revalidate.”
The client/app’s cache policy can determine whether or not a “stale” or even a “not yet stale” value should be returned. Some of these policies are time based (e.g. “okay if stale only for X days”) or location based (“return cached value if it’s there and meets server specified revalidation requirements.) However whatever the app’s cache policy, it must respect the server’s cache directives.
System.Net’s Cache
System.Net.HttpWebRequest’s cache uses the IE cache. This has many benefits: there is a single place for user management perspective. Also, a shared store widens the chance that a recent response might have already been cached. The IE cache (“inet cache”) uses the Temporary Internet Files (“TIF”) to cache results of HTTP requests. Some details:
System.Net.HttpWebRequest’s cache uses the IE cache. This has many benefits: there is a single place for user management perspective. Also, a shared store widens the chance that a recent response might have already been cached. The IE cache (“inet cache”) uses the Temporary Internet Files (“TIF”) to cache results of HTTP requests. Some details:
Understanding the most common cache matrixes
The below table calls out some of the most common caching policies. (Note: We assume that no additional server cache constraints were set other than Expires header.)

Note: If the server does not set the Expires http header, than the expiration=none. In this case, the machine determines what the right “Freshness” time for the resource. By default, this is 1 day but it is configurable.
Note: For System.Net.HttpWebRequest, “Default” policy is somewhat misleading. Unless you explicitly set HttpWebRequest.CachePolicy (or HttpWebRequest.DefaultCachePolicy), the policy is “BypassCache.”
What cache version to use
If your resource files are large & unlikely to change (and having current version is not critical), you should consider:
If it is critical to have the current version of the resource, you should consider:
If you don’t want a unique caching policy, you should stiil:
How to set cache policy
Here is a code snippet:
// eCreate request
HttpWebRequest request =
(HttpWebRequest)WebRequest.Create(requestURI);
// Create & set cache policy
HttpRequestCachePolicy cachePolicy =
new HttpRequestCachePolicy(HttpRequestCacheLevel.Default);
request.CachePolicy = cachePolicy;
// Send request/Get response
HttpWebResponse response = (HttpWebResponse) request.GetResponse();
// Put response in to stream
Encoding enc = Encoding.GetEncoding(1252);
StreamReader responseStream =
new StreamReader(response.GetResponseStream(), enc);
// Manipulate Response stream
// Cleanup
response.Close();
responseStream.Close();
Resources to more deeply understand standard caching
Had a fun quick trip to New York City.
Spent several hours at the Museum of Modern Art. The MOMA is just amazing… it makes the SF MOMA just look so small and modest in comparison. I’m jealous of new yorkers who have such a rich collection in such a beautiful building so close to them.





At the TechEd chalktalk that Ashish and I tag teamed earlier this week, I demo-ed the Woodgrove Financial Application as an XBAP. I also showed loose XAML and an embedded FlowDocument inside of an HTML.
loose XAML with vector graphics (link)
Woodgrove financial app w/ 3D chart as xbap (link)
html page with FlowDocument in IFRAME (link)
Try try out the app.
The last scenario (FlowDocument in HTML) is particularly compelling:
[Apr 17]: Karsten posted the source code for the Woodgrove Finance app a while back. Adding links.
In a chalktalk yesterday, I demo-ed a modified PhotoStore application (you may have seen this demo at last year’s PDC or played with it in the Hands on Labs).
In this version, you can display images bundled with the app as well as those located in your “My Pictures” directory. This works fine as standalone app because it runs in full trust. However, the sandboxed XBAP does NOT have FileIOPermission, and so fails with a SecurityException.
To make both XBAP & Standalone work with the same code base, I demoed the compile switching, runtime switching, and XAML switching tips I wrote about last week.
You can get code here. Or just run the xbap on RC1.
Note: this app uses my VS Flexible Application template.
WinFX has officially been rebranded .NET Framework 3.0.
Also, the offical “.NET Framework 3.0″ Developer Community site has just launched!
There are sub-community sites for Windows Presentation Foundationa> , Windows Communication Foundation, and Windows Workflow Foundation as well as Windows CardSpace (formerly InfoCard).