String.Compare with accents on Framework 4.5 - Windows 8 - by Mauro Sturaro

Status : 

  Won't Fix<br /><br />
		Due to several factors the product team decided to focus its efforts on other items.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.

Sign in
to vote
ID 785931 Comments
Status Closed Workarounds
Type Bug Repros 0
Opened 4/30/2013 8:31:33 AM
Access Restriction Public


The String.Compare return wrong equality on strings that contains minus or single quote character if followed by a character with accent.
The bug disappear if one of the following CompareOptions is also used: IgnoreNonSpace, IgnoreKanaType, IgnoreWidth.

The bug is Only on Framework 4.5 ( also if the application require framework 4.0) on Windows 8 OS.
Any other combination seems to work as expected.

// C# Code sample
using System;
using System.Globalization;

namespace BugStringCompare {
    static class Program {
        static void Main() {

            var s1 = "SELECT 1 as xà";
            var s2 = "SELECT -1 as xà";

            var wrongResult = String.Compare(s1, s2, CultureInfo.InvariantCulture, CompareOptions.IgnoreCase);
            var rightResult = String.Compare(s1, s2, CultureInfo.InvariantCulture, CompareOptions.IgnoreCase | CompareOptions.IgnoreKanaType);

            Console.WriteLine("wrongResult = {0}, rightResult = {1}", wrongResult, rightResult);

Sign in to post a comment.
Posted by Mauro Sturaro on 5/2/2013 at 11:43 PM
Thank you for the important clarification.
I hope this fix will be released asap, because we can change the 800+ code line using string equality and comparison, but we can’t change 3th part component code (Infragistics, Actipro and other).

In the meantime, I must warn our client (mainly banks and financial institutions) to do not upgrade to Windows 8 any PC using our application.

Is there some official KB about this bug that I can reference to explain the reason for my warning?


P.S. just for accuracy note that in my example there is no punctuation at all in the strings.
Posted by Microsoft on 5/1/2013 at 2:26 PM
Just to mention, we are tracking to fix this issue on Windows 8 in the near future. also this issue should be fixed in the future Windows release too.

thanks for reporting the issue
Posted by Microsoft on 5/1/2013 at 12:32 PM
This is valid known bug. The problem is happening when the string has final punctuation. The framework is using Windows sorting behavior when running on Windows 8 (to get some consistency between the framework and the OS). Unfortunately fixing this issue can cause other breaks to other applications taking dependency on the current behavior (like DB apps which is using the current sorting behavior).

You can work around this issue by avoid using punctuation at the end of the string or you can use the following code which will do the right things:

        static int CompareStringUsingSortKey(string s1, string s2)
            SortKey sk1 = CultureInfo.InvariantCulture.CompareInfo.GetSortKey(s1);
            SortKey sk2 = CultureInfo.InvariantCulture.CompareInfo.GetSortKey(s2);
            return SortKey.Compare(sk1, sk2);
Posted by Helen [MSFT] on 4/30/2013 at 8:13 PM
Thanks for your feedback.

We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.
Posted by Macy [MSFT] on 4/30/2013 at 8:50 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(