Or, how to avoid embarrassing bugs in Disk Management caused by Turkish localization.
There’s a classic string localization problem in .NET development known as “The Turkish I”; there are two different versions of the capital I character in the Turkish written language, and they are not equal. Basically, if you’re comparing strings for equality, you’re going to run into issues if you do something like this:
if (string1.ToUpper() == string2.ToUpper())
In Disk Management, I was matching the string “\\PhysicalDisk0” to a variable, and forcing ToUpper() to make sure case wasn’t a factor. The result of ToUpper() on the Turkish string gave me a dotted capital I, which, it turns out, doesn’t match.
A lot of things in Disk Management depend on the physical disk number. If we can’t find a match, just about everything breaks.
So, what should we do instead? Well, I’d like to introduce you to Tentacle Software’s first mandatory coding convention:
public static bool CaseInsensitiveStringMatch(string string1, string string2)
return string.Compare(string1, string2, StringComparison.OrdinalIgnoreCase) == 0;
Which works great. Basic stuff, I know, but it doesn’t hurt to be reminded sometimes that the basics still need to be taken care of.