.NET 5->6 localization regression: Static binding throws during parse
- Dominant language
- C#
- Stars
- 7.7k
- Forks
- 1.3k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 61
Description
* .NET Core Version: 6.0
* Windows version: 19044.1645
* Does the bug reproduce also in WPF for .NET Framework 4.8?: N/A
* Is this bug related specifically to tooling in Visual Studio (e.g. XAML Designer, Code editing, etc...)? No
* Security issues and bugs should be reported privately, learn more via our [responsible disclosure guidelines](https://github.com/dotnet/wpf/blob/main/README.md#reporting-security-issues-and-security-bugs).
**Problem description:**
Binding to a static property that isn't the exact type will throw an exception if the current culture is invariant.
**Actual behavior:**
It might throw with [this string](https://github.com/dotnet/wpf/search?q=XmlLangGetSpecificCulture) from [this method](https://github.com/dotnet/wpf/blob/89d172db0b7a192de720c6cfba5e28a1e7d46123/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Markup/XmlLanguage.cs#L242) but I'm not sure.
**Expected behavior:**
For example: `int` should be able to bind to `TextBox.Text` without throwing an exception if `InvariantGlobalization` is enabled.
**Minimal repro:**
dotnet new wpf -o repro
Edit `MainWindow.xaml.cs`:
```cs
using System.Windows;
namespace repro
{
///
/// Interaction logic for MainWindow.xaml
///
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
public static string IWillNotCauseException { get; set; }
public static int IWillCauseException { get; set; }
}
}
```
and `MainWindow.xaml` :
```xaml
```
1. Run to confirm it works ✔
2. Go into the `.csproj` and add `true`
3. Run again and it will throw ❌
4. Go back into the project file and change `net6.0-windows` to `net5.0-windows`
5. Run again and it will work ✔
Removing static modifier:
```cs
public string IWillNotCauseException { get; set; }
public int IWillCauseException { get; set; }
```
```xaml
```
Will make it work again without exceptions.
Contributor guide
Assessment
This issue has not been assessed yet.