tl;dr: Is it possible to define and register en-BS as a culture on Windows Server 2012 R2?
I'm trying to introduce international currency options to some software I'm working on. That process by itself has not been difficult. I use a culture code such as "en-US" to get a CultureInfo object, and I use NumberFormat from the CultureInfo object to format the currency. Great! We have some clients in the Bahamas, so among the currencies we're looking to support is the Bahamian Dollar, which comes from the culture en-BS.
This worked very well all throughout development. But after we deployed the feature, trying to retrieve the CultureInfo for en-BS came back with the following error.
Culture is not supported.
Parameter name: name
en-BS is an invalid culture identifier.
In researching this error, I learned that cultures are not defined by .NET, but rather by the OS. Windows 10 natively supports en-BS. Great news for my development environment! Windows Server 2012 R2 does not support en-BS. Bad news for our production environment.
So now it looks like I need to utilize CultureAndRegionInfoBuilder. It's not the most convenient solution, but I can make it work. I know nothing about the cultural nuances of Bahamian Dollars, so all I want to do is take the info that is defined on Windows 10 and register it on our 2012 R2 servers. Since I can't just pull up the en-BS CultureInfo via code on the older servers, I thought the next best thing would be to serialize the CultureInfo to a file on my development machine, and deserialize that file on the older servers to then use with CultureAndRegionInfoBuilder.
const string identifier = "en-BS";
string cultureFile = String.Format("{0}-Culture.txt", identifier);
string regionFile = String.Format("{0}-Region.txt", identifier);
IFormatter formatter = new BinaryFormatter();
Stream stream = new FileStream(cultureFile, FileMode.Open, FileAccess.Read, FileShare.Read);
CultureInfo cultureObject = (CultureInfo)formatter.Deserialize(stream);
stream.Close();
stream = new FileStream(regionFile, FileMode.Open, FileAccess.Read, FileShare.Read);
RegionInfo regionObject = (RegionInfo)formatter.Deserialize(stream);
stream.Close();
CultureAndRegionInfoBuilder builder = new CultureAndRegionInfoBuilder(identifier, CultureAndRegionModifiers.None);
builder.LoadDataFromCultureInfo(cultureObject);
builder.LoadDataFromRegionInfo(regionObject);
builder.Register();
It's not the most elegant code I've ever written, but it's straightforward and should be good enough for something I'm going to run once and then archive forever. Unfortunately, when I try to deserialize the CultureInfo object from the file, it once again hits me with the exact same "en-BS is an invalid culture identifier" error, as if it's actively rejecting any culture by that name.
I'm at a loss. Is it at all possible to register en-BS, or any other unsupported culture, to a 2012 R2 server?