Run-time error ‘-2147352567 (80020009) when trying to do SetColumns on a Items collection in Outlook

Problem: SetColumns is failing on non-english versions of windows with the error message below. In fact it was even failing on a English version of windows with English Office 2010 installed.

image

Why would this be happening? When I looked at the system where this code was failing, it looked as if the entire list of comma separated columns was be treaded a one. When I just gave any one of the columns for e.g “FullName” in the SetColumns call, the code seemed to work just fine.

Digging deeper to find out what the problem could be, I looked at the Region and Language settings of the problem machine and found out that the Format was set to Russian (Russia). Could this be causing a problem?

The answer is YES, when we clicked on the Additional Settings on the Format Tab in Regional and Language settings below is what we see:

image

The List separator was set to a semi-colon. I went back to the code and replaced the commas with semi-colon and tested and guess what? The code worked fine with out any issues. Outlook reads the value of List separator and uses it internally to split the string. In the non-working case, since we used a comma, the entire string was be treated as one column.

The bigger question is, how can we make our code independent of the regional settings? The easiest way to get around this issue would be to read the value of List Separator from the registry and use that.

The Separator value is stored under the following registry hive:
[HKEY_CURRENT_USER\Control Panel\International]

And the value you need to read is "sList". After reading the value replace the “,” in your Field list with the separator value read from the registry and then make the call to SetColumns and you should be good to go.

Enjoy!