Bug 54448

Summary: Unable to revert to thread-local storage for CurrentThread.CultureInfo
Product: [Mono] Class Libraries Reporter: Aaron Bockover [MSFT] <abock>
Component: mscorlibAssignee: Rodrigo Kumpera <kumpera>
Severity: normal CC: bojan.rajkovic, kumpera, masafa, mono-bugs+mono, sandy, v-alokul
Priority: High    
Version: 4.8.0 (C9)   
Target Milestone: 15.3   
Hardware: PC   
OS: Mac OS   
Tags: Is this bug a regression?: ---
Last known good build:

Description Aaron Bockover [MSFT] 2017-04-04 14:10:46 UTC
When targeting .NET 4.6, CurrentThread.CultureInfo uses async-local storage to back the property. This now results in regressed and undesirable behavior in Workbooks, since each code cell is an async Task. Thus, setting CurrentThread.CultureInfo does not affect subsequent cells.

On Windows we can revert to thread-local storage for the CurrentThread.CultureInfo by setting the AppContext switch "Switch.System.Globalization.NoAsyncCurrentCulture" to true. On Mono however, this switch is simply ignored. As a result, both
System.Threading.CurrentThread.CultureInfo and System.Globalization.CultureInfo.CurrentCulture are unusable in Mac, iOS, and Android Workbooks.

Doing a little digging, we found that the .NET reference source for AppContextSwitches (the storage backing AppContext) was not actually taken into Mono when integrating other reference sources (e.g. System.Threading.Thread).

This is what AppContextSwitches should be (or some functional analogue):

But this is Mono's AppContextSwitches:

Thus `AppContext.SetSwitch ("Switch.System.Globalization.NoAsyncCurrentCulture", true)` is completely ignored, and the switch will always be false (async-local) instead of true (thread-local).
Comment 2 Rodrigo Kumpera 2017-04-12 20:23:37 UTC
I'll try to make AppContextSwitches more usable.
Comment 3 Rodrigo Kumpera 2017-04-12 20:41:39 UTC
PR against master: https://github.com/mono/mono/pull/4682
Comment 4 Rodrigo Kumpera 2017-04-12 21:12:59 UTC
PR for relnotes: https://github.com/mono/website/pull/278
Comment 5 Marek Safar 2017-06-19 15:36:20 UTC
Closing, all changes have been merged
Comment 6 Alok Kulkarni 2017-07-13 09:50:38 UTC
Hi @Aaron Bockover, Looks like development bug, will you please help me out to verify this?