wpf: Using a German UI Culture crashes WPF application
- .NET Core Version: 3.0.100-preview6-011805 and 3.0.100-preview6-011865
- Windows version: Windows 7 and Windows 10 1903
- Does the bug reproduce also in WPF for .NET Framework 4.8?: No
Problem description: As a Dutch guy I always wanted to say there is a problem with the German culture, I finally manage to do so without offending someone.
When showing a WPF window with the UI culture set to German, the application crashes.
Actual behavior:
System.Windows.Markup.XamlParseException
HResult=0x80131501
Message=Zeilennummer "10" und Zeilenposition "10" von "Durch den Aufruf des Konstruktors für Typ "System.Windows.Controls.TextBox", der den angegebenen Bindungseinschränkungen entspricht, wurde eine Ausnahme ausgelöst.".
Source=PresentationFramework
StackTrace:
at System.Windows.Markup.XamlReader.RewrapException(Exception e, IXamlLineInfo lineInfo, Uri baseUri)
at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
at System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri)
at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
at Test.MainWindow.InitializeComponent() in C:\Projects\Microsoft\Test\WpfCultureBug\MainWindow.xaml:line 1
Inner Exception 1:
ArgumentException: Requested value 'EINFG' was not found.
“EINFG” is short for einfügen, which means insert.
Expected behavior: No exception.
Minimal repro: https://github.com/Lakritzator/WpfCultureBug
In general just calling:
CultureInfo.CurrentUICulture = CultureInfo.GetCultureInfo("de-DE");
Before showing a text-box crashes the application.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 16 (8 by maintainers)
Commits related to this issue
- https://github.com/dotnet/wpf/issues/684 was fixed with https://github.com/dotnet/wpf/issues/684, available in 3.0.100-preview7-012267, now the workarounds can be removed. — committed to dapplo/Dapplo.Microsoft.Extensions.Hosting by Lakritzator 5 years ago
- Use Preview 5 due to https://github.com/dotnet/wpf/issues/913 https://github.com/dotnet/wpf/issues/684 — committed to NuGetPackageExplorer/NuGetPackageExplorer by deleted user 5 years ago
@AlexanderTaeschner dotnet core 3.0 is in preview, if you don’t want to hit critical bugs don’t use it yet. I decided to be an early adopter, and was prepared for the pain this brings.
In the current “nightly” version of the dotnet core 3.0 SDK, at the time of writing this it’s 3.0.100-preview7-012393, the code for fixes for another WPF Culture issue is not available yet. As it’s unrealistic such changes can be “backported” without a lot of work, I rather have the dotnet core team move forwards to a new preview or release, than spending time to patch preview versions.
You could go back to the preview 5, which AFAIK should solve your issue.
You can also add the following workaround to your, hopefully also in preview, software. Place this somewhere at the startup before the UI is shown:
CultureInfo.CurrentUICulture = CultureInfo.GetCultureInfo("en-US");
Although this forces your UI to be in US English, at least your application should not be crashing with a culture dependent bug! Note: there might still be plenty of other bugs though.
Closing as this was fixed by #796
@Lakritzator: the source is available now.
https://github.com/dotnet/wpf/tree/master/src/Microsoft.DotNet.Wpf/src/PresentationFramework/Resources/xlf.
PresentationFramework had some key strings that were translated to German when they shouldn’t have been (e.g., ‘Insert’) which caused lookup failures. This needs to be fixed in our internal repo. I’ll follow up when the fix is in the nightly build. Thanks again for the bug report.
Thanks, @Lakritzator. I’ll take a look.