Host (useful for support):
Version: 3.0.0-preview5-27626-15
Commit: 61f30f5a23
Does the bug reproduce also in WPF for .NET Framework 4.8?: No, Binding works as expected
Problem description:
Binding an ExpandoObject in WPF Control (ex. Textbox.Text) throws BindingExpression Error in .NET Core WPF, but Binding works in .NET Framework (4.8 and 4.7.2)
Actual behavior:
Throwing BindingExpression Error
System.Windows.Data Error: 40
BindingExpression path error: 'Test' property not found on 'object' ''ExpandoObject' (HashCode=58204539)'. BindingExpression:Path=TestProperty.Test; DataItem='MainViewModel' (HashCode=16745860); target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')
Expected behavior:
Binding Property as in .NET Framework
Minimal repro:
using System.ComponentModel;
using System.Dynamic;
using System.Runtime.CompilerServices;
namespace WpfApp1.ViewModels
{
public class MainViewModel : INotifyPropertyChanged
{
public MainViewModel()
{
TestProperty = new ExpandoObject();
TestProperty.Test = "abc";
TestProperty.ABC = "xyz";
}
private dynamic TestPropertyValue = default;
public dynamic TestProperty { get { return TestPropertyValue; } set { TestPropertyValue = value; NotifyPropertyChanged(nameof(TestProperty)); } }
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}
<Window x:Class="WpfApp1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:viewmodels="clr-namespace:WpfApp1.ViewModels" mc:Ignorable="d" DataContext="{DynamicResource ResourceKey=MainVM}">
<Window.Resources>
<viewmodels:MainViewModel x:Key="MainVM" />
</Window.Resources>
<StackPanel Orientation="Vertical">
<TextBlock Text="{Binding Path=TestProperty.Test}"/>
<TextBlock Text="{Binding Path=TestProperty.ABC}"/>
</StackPanel>
</Window>
@pocki: Great bug. Thanks for the report and minimal repro.
I've reproduced it locally and am investigating today. Thanks.
MS.Internal.SystemCoreHelper.IsIDynamicMetaObjectProvider is returning false for System.Dynamic.ExpandoObject which is causing the PropertyPath resolution to fail. The cause is a possible logic error in the AssemblyLoader preventing System.Core from being loaded.
Marking this as approved since we now understand this to be a bug. We really do need to fix this in P7.
/cc @ryalanms, @grubioe
Most helpful comment
@pocki: Great bug. Thanks for the report and minimal repro.
I've reproduced it locally and am investigating today. Thanks.