Considering
asp.net 4 with mvc 5.2.3 and .net 4.6.1
I want to change the globalization of CurrentCulture support based on some host-related queries.
A Owin-Middleware that establishes a culture.
A simplified version that creates the behavior:
public override async Task Invoke(IOwinContext context) { var culture = new CultureInfo("es-ES"); Thread.CurrentThread.CurrentCulture = culture; Thread.CurrentThread.CurrentUICulture = culture; CultureInfo.CurrentCulture = culture; CultureInfo.CurrentUICulture = culture; await Next.Invoke(context); }
Problem
Culture is not preserved. So, for example, the web controller does not have the culture that was installed in the middleware.
This does not seem to be related to the thread related issue. As when calling only some methods and waiting for their culture is preserved.
Although it works with 4.5.1. (I already used it that way in other projects) And when I change the version of httpRuntime as follows:
<httpRuntime targetFramework="4.5.1" />
everything works like a charm.
I cannot find any documented changes for this. any hint? I can play it with an empty new ASP Project. Any tips?
Addition.
This problem is not related to maintaining the culture in the stream, as it works great!
CultureInfo.CurrentCulture = new CultureInfo("en-GB"); await Foo(); Debug.WriteLine(Thread.CurrentThread.CurrentCulture);// Works is en-gb } private Task Foo() { Debug.WriteLine(Thread.CurrentThread.CurrentCulture);// Works is en-gb return Task.FromResult(true); }
source share