Marketplace Tip: CultureInfo.InvariantCulture

 image

After releasing a ‘Lite’ version of my Jamster application just before Christmas I have received a lot of comments from foreign downloaders that point to an obvious issue when running in other languages/culture settings.

Of course I  had tested code under several different language settings in the past, but was conscious that I hadn’t done so recently. 

A quick check running the emulator in French (see left – Settings->Region & Language) quickly revealed the culprit and an easy fix:

image

Without the second parameter the parsing assumes culture specific attributes, which are often undesirable.

http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.invariantculture.aspx

 

image

3 thoughts on “Marketplace Tip: CultureInfo.InvariantCulture

  1. Of course it all depends what you’re parsing. If it’s user input then it’s likely they’ll enter using their own cultural bias, and using the InvarientCulture may fail. So for user input you should be using CultureInfo.CurrentUICulture, and of course the same for display output.

    Also note that Code Analysis has rules for missing culture parameters on lots of functions, but you need one of the professional VS SKUs for that.

Leave a Reply

Your email address will not be published.