Looking to implement exception message translation as shown in Exception messages in English? I'd like unit tests so this requires being able to produce the messages in a different language. That doesn't quite work out though; code like
Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("de-DE");
Console.WriteLine(DirectoryNotFoundException().Message);
Always produces the English version "Attempted to access a path that is not on the disk.".
Figuring I'm missing something and following instructions I installed the German .NET Framework 4.7.2 language pack for testing this in an application with TargetFrameworkVersion=v4.7.2 Visual Studio 2017, no change.
Wanting to try the same in Visual Studio 2022, with the same application but targetting v4.8, I also tried to install the German .NET Framework 4.8 language pack, but that installer doesn't complete. The tranlated message is (almost ironically the installer UI is completely in German) ".NET Framework 4.8 (Deutsch) or a later version is already installed on this computer."
Am I doing something wrong here? I mean I can write applications targetting different framework versions so I assume the prerequisites for language packs are there? Do I need to install something else, or in a different way?
And is there a way to figure out in code or otherwise why the GetCultureInfo
call doesn't return a culture, e.g. where does it go looking for resource files, and is there perhaps a way to correct that?