Saturday, January 21, 2006

Deploying to a Windows Mobile device

A few months ago I got myself a Dell Axim X50v, convincing myself that it was a "good investment" as I'd be able to look into developing for the Pocket PC. In time-honoured fashion, I've never actually managed to get past a quick "Hello World" program on it, although I did think it was pretty cool the way you could just hit F5 in Visual Studio and up came the app on my PDA.

Anyway, I just decided I'd give it another bash with Visual Studio 2005 (Last time I tried I was using 2003) and upon hitting F5 I got the less than useful message "The configuration data for this product is corrupt. Contact your support personnel". Fortunately, Google is here to save the day again, and I found a post on a message board somewhere saying to close down Visual Studio, delete the directory C:\Documents and Settings\<localuser>\Local Settings\Application Data\Microsoft\CoreCon, and then restart and try again.

Did the trick for me, and I hope it works for you too if you find yourself here on a Google search of your own.

I get the impression that this folder is/was an artifact of an old beta install of VS2005 although I don't know that for certain. If anyone knows for sure where it comes from please do feel free to enlighten me!

Wednesday, January 18, 2006

Serialization and type versions

After stating in my previous post that I write messages in en-GB, I go and ruin that by putting "Serialization" in the title of this one. Go figure.

Another nice addition in .NET 2.0 are five attributes in the System.Runtime.Serialization namespace. These help with telling v2 of a class how to cope when dealing with objects of type v1. The attributes are as follows:


Read the docs for usage, but essentially if you mark the new member fields in v2 with [OptionalField] then it doesn't fall over when attempting to deserialize an object of type v1, as it knows that the info might be missing. You can then use a method marked with [OnDeserialized] to do sensible things like set a default value for a missing field for example.

Wednesday, January 11, 2006

"Neutral" Resources

The system may have a concept of a "neutral language", but in the real world I tend to write my default messages in a concrete language (which for me is en-GB). When it comes to doing localisation, there's no need to then duplicate the effort and create a separate en-GB resources file - simply mark your "neutral" version with what it actually is.

You can do this with an attribute (in AssemblyInfo.cs), like so:

[assembly: NeutralResourcesLanguage("en-GB")]

EDIT: Should have guessed this already really, but I've just realised that in VS2005 with its new GUI to edit the AssemblyInfo.cs file, this attribute is a drop down inside the Assembly Information page anyway. Simplicity itself.

Tuesday, January 10, 2006

Null coalescing operator

Fancy title to get things going.

This is one of those things that'll be second nature once I start using it in anger, but until I do that, I'll consistently forget it.

C# 2.0 introduces nullable types, and the null coalescing operator (??) is a binary operator that works pretty much the same way as T-SQL's ISNULL() function.

So for:
a ?? b

ISNULL(a, b)

One small caveat here is that b could of course be a nullable type as well, in which case the result of a ?? b is still a nullable type. If it's not, the result isn't either. See example below (ripped from C# 2.0 spec).

int? x = GetNullableInt();
int? y = GetNullableInt();
int? z = x ?? y;
int i = z ?? -1;

First post

I figured it was probably fairly obligatory to have a "first post" post. So here it is. At this point I have absolutely no idea if I'll continue this blog beyond the initial novelty value length of a day or two.

Essentially my only motivation for doing this is as a repository for little tidbits of info I find out whilst wading my way through the world of .NET programming, as I've lost count of the number of times I've thought, "I remember reading about how to do that... now if only I could find it..."

With any luck if I convince myself to dump it in here then I'll be able to find it again later. So if you've got no interest in programming, look elsewhere. I don't feel the need to share with the world what I had for tea last night, who I babysat for at the weekend, or why I'll be choosing gloss rather than matt paint for decorating.