Fix NullReferenceException thrown when using CurrentCulture (#12281)
authorTarek Mahmoud Sayed <tarekms@microsoft.com>
Wed, 14 Jun 2017 23:36:24 +0000 (16:36 -0700)
committerGitHub <noreply@github.com>
Wed, 14 Jun 2017 23:36:24 +0000 (16:36 -0700)
commit018e5252ed8427aeffea43a2935114149e10bc1b
treee9132fb3dcc166cf8612731d77dd7e62fcbcde6f
parent7f00fec141ca1b222b1c113d2de055e80728bb99
Fix NullReferenceException thrown when using CurrentCulture (#12281)

CurrentCulture used the static field s_userDefaultCulture which used to store the current culture. We always ensure this field is initialized all the time. When we introduced the v2.0 added APIs, we have added ClearCachedData(). This method was setting s_userDefaultCulture to null which can cause any other thread to throw this NullReferenceException if it is using s_userDefaultCulture. Here is example of such stack

System.NullReferenceException : Object reference not set to an instance of an object.
Stack Trace :
   at System.Globalization.NumberFormatInfo.get_CurrentInfo()
   at System.Double.ToString(String format, IFormatProvider provider)
src/mscorlib/src/System/Globalization/CultureInfo.cs