I have a List of objects and need to sort the list based on one of the properties. This sorting should be done based on a specified culture. I found many resources explaining how this could be achieved and implemented them with success locally. However, when I deploy the code, sorting does not appear to be done based on the specified culture.
I have tried using both LINQ's OrderBy and List's Sort, both with the overload which accepts a StringComparer.
These are the snippets:
nor = norwegianStrings.OrderBy(x => x, StringComparer.Create(new System.Globalization.CultureInfo("no-NO", true), true)).ToArray();
danishStrings.Sort(StringComparer.Create(new System.Globalization.CultureInfo("da-DK"), true));
Both of these are working locally, and for reference I have tried both Array and List. When deployed though, it just sorts normally, like InvariantCulture. I have also tried to manually set Thread.CurrentThread.CurrentCulture and then using that in the StringComparer.
I have tried to add the cultures in Startup via
services.Configure<RequestLocalizationOptions>(options =>
{
var supportedCultures = new[] { "no-NO", "sv-SE", "da-DK" };
options.SetDefaultCulture(supportedCultures[0])
.AddSupportedCultures(supportedCultures)
.AddSupportedUICultures(supportedCultures);
});
I am at a loss. Any idea why this could be happening? How can I solve this, or troubleshoot further?
Thanks in advance!
The issue was indeed regarding locales available in the machine.
App-local ICU was a no-go, or at least I was unable to get my container up and running with it. The dockerfile already included
RUN apk add --no-cache icu-libs, but I did find that in some distros, icu-libs only included english locales.So, I also had to include
RUN apk add --no-cache icu-data-full.Nothing required in Program.cs or Startup.cs. Nothing required in .csproj, just make sure to include the CORRECT icu in the machine.
Thanks for the help, guys!