Monday, February 28, 2005 - Posts

Isolated Storage

A while ago I blogged that I discovered that attempting to write to app.config was a bad idea. The officially sanctioned solution for per-user settings is writing to the user's profile directory which is accessible in .NET by using Isolated Storage (IanG wrote a good article about this).

Up till my earlier blog post I believed that the app.config file was a good place to update settings that might be changed at runtime. I even adapted code from a Code Project article "Save and Restore User Preferences" to help me read and write settings easily, added caching, and used it in all my applications. The advantages seemed to be that the app.config file is XML, so it was easily read and written, and I knew the file would exist as it's installed with apps. But, it turns out that app.config is actually a deployment kind of file. The clincher came when I installed an app on a user's PC and found they could not write to the directory where app.config was stored...so, changes to it, especially per-user settings, should be stored using Isolated Storage.

There's a few good articles to get anyone else interested in Isolated Storage started:

I eventually settled on Rocky Lhotka's “Adventures in Visual Basic .NET: Storing User Configurations” solution which I pretty much used as-is. It takes a little bit more thought to set up than some of the other suggestions (but is strongly-typed), and having one-line Save & Restore methods is a real bonus, plus I can change the storage to INI files or the registry if I really want.

OT: Windows Plays Soccer

It's probably done the rounds already, but I found the following quote pretty funny (via Random Developments, originally posted at Max Barry's blog):

Windows plays soccer; Linux plays rugby. In soccer (sorry, to me this is football), whenever one player makes the slightest contact with another, he collapses to ground, writhing in agony and clutching at his ankle. Everyone gathers around and looks very worried until the referee holds up a yellow card and then—amazing!—the player springs up again, completely cured. So too Windows: as soon as anything goes wrong with any program, the whole thing collapses in a screaming heap, and requires a reboot. Linux, on the other hand, shrugs off application failures like a rugby player ignores broken fingers. Programs crash, but Linux keeps going.

Tee hee hee...