CurrentCulture not available in DNX Core 5.0
I'm having a problem diagnosing a dependency issue using the latest (5/1/2015) version of Visual Studio 2015 RC 14.0.22823.1 D14REL.
The following code does not compile or throw this error:
Severity Code Description Project File Line
Error CS1061
'Thread' does not contain a definition for 'CurrentCulture' and no
extension method 'CurrentCulture' accepting a first argument of type
'Thread' could be found (are you missing a using directive or an assembly
reference?)
ServiceLibrary.DNX Core 5.0
using System;
using System.Globalization;
using System.Threading;
namespace ServiceLibrary
{
public class CultureService
{
public void SetCulture(string cultureCode = "fr-FR")
{
Thread.CurrentThread.CurrentCulture = new CultureInfo(cultureCode);
}
}
}
Hovering over Visual Studio Visual Studio displays a pop-up window that displays:
Here is the .json project
{
"version": "1.0.0-*",
"description": "",
"authors": [ "" ],
"tags": [ "" ],
"projectUrl": "",
"licenseUrl": "",
"dependencies": {
"System.Threading": "4.0.10-beta-22816",
"System.Threading.Thread": "4.0.0-beta-22816",
"System.Globalization": "4.0.10-beta-22816"
},
"frameworks": {
"dnx451": { },
"dnxcore50": {
"dependencies": {
"System.Collections": "4.0.10-beta-22816",
"System.Linq": "4.0.0-beta-22816",
"Microsoft.CSharp": "4.0.0-beta-22816",
}
}
}
}
I hope someone can help figure out where the problem is.
thank
+3
source to share
1 answer
Culture namespaces are in different places between DNCCORE50 and full size DNX451, so you need to use compiler directives. Hope this helps.
#if DNX451
Thread.CurrentThread.CurrentCulture = new CultureInfo(cultureCode);
#elif DNXCORE50
CultureInfo.CurrentCulture = new CultureInfo(cultureCode);
#else
#error No Implementation for the target DNX
#endif
+2
source to share