From 630c1db446d199cb8ba18bda1126f2fbb3de67f0 Mon Sep 17 00:00:00 2001 From: Viktor Hofer Date: Mon, 19 Jun 2017 22:59:38 +0200 Subject: [PATCH] Fixing CompareInfo AssemblyMode.Full serialization between Core <--> Desktop (dotnet/coreclr#12365) * Fixing CompareInfo AssemblyMode.Full serialization * Adding reason why culture field is introduced Commit migrated from https://github.com/dotnet/coreclr/commit/b2cd406d76546d075cdcb79c3255c113f7f1dbfa --- .../mscorlib/src/System/Globalization/CompareInfo.cs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/coreclr/src/mscorlib/src/System/Globalization/CompareInfo.cs b/src/coreclr/src/mscorlib/src/System/Globalization/CompareInfo.cs index b7ab5ad..bfdbdc5 100644 --- a/src/coreclr/src/mscorlib/src/System/Globalization/CompareInfo.cs +++ b/src/coreclr/src/mscorlib/src/System/Globalization/CompareInfo.cs @@ -75,6 +75,8 @@ namespace System.Globalization // _invariantMode is defined for the perf reason as accessing the instance field is faster than access the static property GlobalizationMode.Invariant [NonSerialized] private readonly bool _invariantMode = GlobalizationMode.Invariant; + + private int culture; // Do not rename (binary serialization). The fields sole purpose is to support Desktop serialization. internal CompareInfo(CultureInfo culture) { @@ -234,14 +236,26 @@ namespace System.Globalization private void OnDeserialized() { - if (m_name != null) + // If we didn't have a name, use the LCID + if (m_name == null) + { + // From whidbey, didn't have a name + CultureInfo ci = CultureInfo.GetCultureInfo(this.culture); + m_name = ci._name; + } + else { InitSort(CultureInfo.GetCultureInfo(m_name)); } } [OnSerializing] - private void OnSerializing(StreamingContext ctx) { } + private void OnSerializing(StreamingContext ctx) + { + // This is merely for serialization compatibility with Whidbey/Orcas, it can go away when we don't want that compat any more. + culture = CultureInfo.GetCultureInfo(this.Name).LCID; // This is the lcid of the constructing culture (still have to dereference to get target sort) + Contract.Assert(m_name != null, "CompareInfo.OnSerializing - expected m_name to be set already"); + } ///////////////////////////----- Name -----///////////////////////////////// // -- 2.7.4