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)

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

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

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?