Binding to explictly qualified property on notifying object causes runtime exception when using `Binding(string path)` ctor.
- Dominant language
- C#
- Stars
- 7.7k
- Forks
- 1.3k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 61
Description
### Description
When creating a binding via markup, you have the option of using the default parameterless constructor and setting the path using `Path=` or using the one that takes the path as the first constructor argument. The latter is usually preferable because it's less verbose and ensures the path is always first, but it takes a `string` rather than a `PropertyPath`. When using the latter and binding to a qualified property path on an `INotifyPropertyChanged` implementing type, a runtime exception is thrown. There is no issue if the source item does not implement `INotifyPropertyChanged`.
Qualified segments are where you use `.({TypeName}.{PropertyName})`, to access properties that aren't directly known by reflection.
### Reproduction Steps
```csharp
using System.ComponentModel;
using System.Windows;
namespace TestWpfApp;
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
}
public class ViewModelContainer
{
public IViewModel ViewModel { get; set; } = new CustomViewModel();
}
public class CustomViewModel : IModel, ICustomModel, INotifyPropertyChanged
{
public string CustomProperty { get; set; } = "Custom Property Text!";
public event PropertyChangedEventHandler? PropertyChanged;
}
public interface IViewModel
{
}
public interface ICustomViewModel
{
string CustomProperty { get; set; }
}
```
```xaml
```
### Expected behavior
Using either constructor on a `Binding` should produce the same result, and ideally no cryptic exception.
### Actual behavior
> System.ArgumentNullException: 'Value cannot be null. Arg_ParamName_Name'
And probably an application crash.
### Regression?
No idea, I doubt it.
### Known Workarounds
`Path=` must be added, but working this out is not at all obvious. For example:
```xaml
```
### Impact
It's not the most common type of binding, but seems like it could be present in many projects.
### Configuration
.NET 8, Windows, x64.
Doesn't seem likely to be specific to this configuration.
### Other information
I'm not sure, but I think the issue lies here:
https://github.com/dotnet/wpf/blob/4fb8416e780445d0877aa6eede32aaf628e1bcab/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/PropertyPathWorker.cs#L873-L876
where `propertyName` is `null`.
Contributor guide
Assessment
This issue has not been assessed yet.