Wpf: Using a German UI Culture crashes WPF application

Created on 13 May 2019  路  16Comments  路  Source: dotnet/wpf

  • .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.

issue-type-bug regression

All 16 comments

Thanks, @Lakritzator. I'll take a look.

Let me know if you need anything else, I tried to find the sources so I could try to fix it myself. but I couldn't find them in the WPF repository yet... did I miss it, or is this part of the stuff that is still coming?

edit: Sorry, I see you provided this information already.

As reported in the initial comment I've tested with 3.0.100-preview6-011805 and 3.0.100-preview6-011865
Yes, must be a regression as this worked just fine for the last weeks... don't know when it started.

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 for the feedback and you are welcome!

P.S.
Any idea when the sources for the rest of WPF will be available, so I might have been able to fix this myself?

Yes, apologies that all .NET Core WPF source isn't on the public repo yet. All source will be on the public repo between now and September when WPF for .NET Core 3.0 is released: https://github.com/dotnet/core/blob/master/roadmap.md.

@ryalanms Thanks for the update, it's really great to have the sources available.

So I tried to have a look at this, but haven't been able to figure out what is going on.

The Strings.de.xlf seems to be fine, but oddly enough it's only this file which has translations for the insert, which can be seen in the KeyToggleInsert. This might mean that the issue is only visible when using the German culture!

I checked the KeyGestureConverter but it looks fine.

My biggest problem is that I am uncertain what code is actually in what build, there are so many branches (!!!) and I couldn't find the big picture which might explain how things work together.
Maybe the issue has already been fixed, and I am looking at the correct code, but my current dotnet-sdk (3.0.100-preview6-012085) just didn't get those changes yet...?

I also couldn't get a WPF build to function yet, when I had some time to try this out I was restricted by a very inflexible firewall.

So before I continue to invest time in this, can you tell me (or point me to a document) how I can figure out how the dotnet core 3.0 sdk and WPF build versions are related?

Thanks @Lakritzator. There is an immediate fix here, #796, but I'm reviewing everything all the loc infrastructure to understand why these strings were translated and to prevent them from being translated in the future.

I'm a bit confused while the translations seemed to make sense.

Why would it say translation, but the text is still in English?
I was actually thinking it would be a code issue, as the XLF file was looking fine to me...

Yes, you are correct. The satellite assemblies are generated per language, and at runtime, the strings are looked up in the satellite assembly. These should have already been moved in to static strings in the source.

Closing as this was fixed by #796

Fix seems to be available in 3.0.100-preview7-012267

Just experienced this crash after updating to the latest official .Net Core 3 Preview 6, published yesterday. This is very unfortunate! Could you publish a Preview 6.1 with the fix, since this is a blocker for all WPF applications running on a German Windows!

@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.

Was this page helpful?
0 / 5 - 0 ratings