A not so clear Visual Studio code analysis message (CA1308)

While writing a custom stsadm command for SharePoint (more on that in a future post) and having to do something based on the command the user typed in, I used ToLower(CultureInfo.InvariantCulture) on the command string to be able to check without the hassle of differences in casing. When I ran code analysis on my project, I got this somewhat cryptic message:

CA1308 : Microsoft.Globalization : In method 'CommandParser.Run(string, StringDictionary, out string)', replace the call to 'string.ToLower(CultureInfo)' with String.ToUpperInvariant().

So in order to solve a code analysis warning I should change lowercasing a string to a call to ToUpperInvariant? That seems a bit strange, right? Because I was almost sure this could not be a typo, I searched around a bit. When you search for the error number, you get an explanation from Microsoft through the MSDN article Normalize strings to uppercase [1]. Apparently there's an issue with a small group of characters which are unable to round trip when converted to lowercase. For more information: have a look at Michael Kaplan's post Get off my (lower) case! (or: Casing, the 1st) which explains it pretty well [2].

Hope this helps some of you ;)

[1] http://msdn.microsoft.com/en-us/library/bb386042.aspx
[2] http://blogs.msdn.com/michkap/archive/2004/12/02/273619.aspx

Comments

# re: A not so clear Visual Studio code analysis message (CA1308)

Thursday, March 04, 2010 4:00 PM by Shaun

Hells yes it helped!  I was wondering why StyleCop was telling me to make things uppercase..  Damn StyleCop, always thinking it knows best ;)

# re: A not so clear Visual Studio code analysis message (CA1308)

Wednesday, January 25, 2012 1:38 PM by Jeroen van der Meer

Rick, thanks, I was wondering why fxcop.... now I know.

Nice to stumble upon you this way!

# re: A not so clear Visual Studio code analysis message (CA1308)

Thursday, January 26, 2012 10:46 AM by Rick van den Bosch

@Jeroen yes it is!

It's a small world after all... ;)

Leave a Comment

(required) 
(required) 
(optional)
(required) 
Please add 1 and 1 and type the answer here: