<CompatSortNLSVersion> Element

Specifies that the runtime should use legacy sort orders when performing string comparisons.




Attributes and Elements

The following sections describe attributes, child elements, and parent elements.


Attribute Description
enabled Required attribute.

Specifies the locale ID whose sort order is to be used.

enabled Attribute

Value Description
4096 The locale ID that represents an alternate sort order. In this case, 4096 represents the sort order of the .NET Framework 3.5 and earlier versions.

Child Elements


Parent Elements

Element Description
configuration The root element in every configuration file used by the common language runtime and .NET Framework applications.
runtime Contains information about runtime initialization options.


Because string comparison, sorting, and casing operations performed by the System.Globalization.CompareInfo class in the .NET Framework 4 conform to the Unicode 5.1 standard, the results of string comparison methods such as String.Compare(String, String) and String.LastIndexOf(String) may differ from previous versions of the .NET Framework. If your application depends on legacy behavior, you can restore the string comparison and sorting rules used in the .NET Framework 3.5 and earlier versions by including the <CompatSortNLSVersion> element in your application's configuration file.


Restoring legacy string comparison and sorting rules also requires the sort00001000.dll dynamic link library to be available on the local system.

You can also use legacy string sorting and comparison rules in a specific application domain by passing the string "NetFx40_Legacy20SortingBehavior" to the SetCompatibilitySwitches method when you create the application domain.


The following example instantiates two String objects and calls the String.Compare(String, String, StringComparison) method to compare them by using the conventions of the current culture.

using System;

enum StringComparisonResult
    precedes = -1,
    equals = 0,
    follows = 1,

public class Example
   public static void Main()
      string str1 = new string( new char[] {'\u0219', '\u021B', 'a' });
      string str2 = "a";

      Console.WriteLine("{0} {1} {2} in the sort order.",
                        (StringComparisonResult) String.Compare(str1, str2, StringComparison.CurrentCulture),
Enum StringComparisonResult As Integer
    precedes = -1
    equals = 0
    follows = 1
End Enum

Module Example
    Public Sub Main()
        Dim str1 As String = ChrW(&h219) + ChrW(&h21B) + "a"
        Dim str2 As String = "a"

        Console.WriteLine("{0} {1} {2} in the sort order.", _
                          str1, _
                          CType(String.Compare(str1, str2, StringComparison.CurrentCulture), StringComparisonResult), _
    End Sub
End Module

When you run the example on the .NET Framework 4, it displays the following output:

sta follows a in the sort order.  

This is completely different from the output that is displayed when you run the example on the .NET Framework 3.5:

sta equals a in the sort order.  

However, if you add the following configuration file to the example's directory and then run the example on the .NET Framework 4, the output is identical to that produced by the example when it is run on .NET Framework 3.5.

<?xml version ="1.0"?>  
      <CompatSortNLSVersion enabled="4096"/>  

See also