Bug 54448 - Unable to revert to thread-local storage for CurrentThread.CultureInfo
Summary: Unable to revert to thread-local storage for CurrentThread.CultureInfo
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: mscorlib (show other bugs)
Version: 4.8.0 (C9)
Hardware: PC Mac OS
: High normal
Target Milestone: 15.3
Assignee: Rodrigo Kumpera
URL:
Depends on:
Blocks:
 
Reported: 2017-04-04 14:10 UTC by Aaron Bockover [MSFT]
Modified: 2017-07-15 03:32 UTC (History)
6 users (show)

See Also:
Tags:
Is this bug a regression?: ---
Last known good build:


Attachments

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):
  https://github.com/mono/mono/blob/master/mcs/class/referencesource/mscorlib/system/AppContext/AppContextSwitches.cs

But this is Mono's AppContextSwitches:
  https://github.com/mono/mono/blob/master/mcs/class/corlib/ReferenceSources/AppContextSwitches.cs

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?

Note You need to log in before you can comment on or make changes to this bug.