Search code examples
c#mscorlib

How to use a specific version of System.Globalization?


I have a UWP app that uses Microsoft.NetCore.UWP as a dependency.

I want to use System.Globalization library, but the one included in mscorlib, not the one included in NetCore.

That is because the latter has several additional methods I need, f. e. CultureInfo.GetCultures(...).

How do I use it? Right now my using System.Globalization point to this file:

#region Assembly System.Globalization, Version=4.0.10.0, Culture=neutral, PublicKeyToken=...
// C:\Users\...\.nuget\packages\system.globalization\4.3.0\ref\netcore50\System.Globalization.dll
#endregion

What I need is this:

#region Assembly mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=...
// C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\mscorlib.dll
#endregion

Solution

  • K, after some investigation...

    You can use the .net standard 2.0 compatible version of System.Globalization in your project to allow calling CultureInfo.GetCultures(CultureTypes.AllCultures) but, first you need to make sure you are targeting the *Fall creator's update version

    My application properties

    What I currently have installed

    Once you have updated that then install the package from nuget.

    My nuget packages installed

    The min version of UWP

    Once I've done that the following runs fine.

    var testresult = CultureInfo.GetCultures(CultureTypes.AllCultures);