Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit f028f7d

Browse files
committed
Fixing CompareInfo AssemblyMode.Full serialization
1 parent 2baf2ba commit f028f7d

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/mscorlib/src/System/Globalization/CompareInfo.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ public partial class CompareInfo : IDeserializationCallback
7575
[NonSerialized]
7676
private readonly bool _invariantMode = GlobalizationMode.Invariant;
7777

78+
private int culture; // Do not rename (binary serialization)
79+
7880
internal CompareInfo(CultureInfo culture)
7981
{
8082
m_name = culture._name;
@@ -233,14 +235,26 @@ private void OnDeserialized(StreamingContext ctx)
233235

234236
private void OnDeserialized()
235237
{
236-
if (m_name != null)
238+
// If we didn't have a name, use the LCID
239+
if (m_name == null)
240+
{
241+
// From whidbey, didn't have a name
242+
CultureInfo ci = CultureInfo.GetCultureInfo(this.culture);
243+
m_name = ci._name;
244+
}
245+
else
237246
{
238247
InitSort(CultureInfo.GetCultureInfo(m_name));
239248
}
240249
}
241250

242251
[OnSerializing]
243-
private void OnSerializing(StreamingContext ctx) { }
252+
private void OnSerializing(StreamingContext ctx)
253+
{
254+
// This is merely for serialization compatibility with Whidbey/Orcas, it can go away when we don't want that compat any more.
255+
culture = CultureInfo.GetCultureInfo(this.Name).LCID; // This is the lcid of the constructing culture (still have to dereference to get target sort)
256+
Contract.Assert(m_name != null, "CompareInfo.OnSerializing - expected m_name to be set already");
257+
}
244258

245259
///////////////////////////----- Name -----/////////////////////////////////
246260
//

0 commit comments

Comments
 (0)