<CompatSortNLSVersion> Element

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

<configuration> Element
  <runtime> Element
    <CompatSortNLSVersion> Element
<CompatSortNLSVersion  
   enabled="4096"/>

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

Attributes

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

None.

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.

Important noteImportant

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.", 
                        str1, 
                        (StringComparisonResult) String.Compare(str1, str2, StringComparison.CurrentCulture),  
                        str2);       
   }
}

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 the .NET Framework 3.5.

<?xml version ="1.0"?>
<configuration>
   <runtime>
      <CompatSortNLSVersion enabled="4096"/>
   </runtime>
</configuration>
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2015 Microsoft