Open Cricle opened 3 years ago
@Cricle Is the Bd null?
是不是 Bd
这个值是空的?
@Cricle Is the Bd null?
是不是
Bd
这个值是空的?
No, it is define in xaml. 不是,它是在XAML定义的
@Cricle Please attach a full repro, and more of the stack trace. Also a crash dump, if possible.
AvTrace.AntiFormat
in the stack trace suggests that someone is trying to print an error message to the trace output sink (typically the VS output window). Does this happen in .NET 5.0?
A null-reference error suggests that the error message is null. This shouldn't happen, but perhaps something is wrong with your installation of .NET Framework, maybe the error message lookup fails because of a localization problem. A crash dump might shed light on this; the XAML and code-behind is definitely not enough.
@Cricle Please attach a full repro, and more of the stack trace. Also a crash dump, if possible.
AvTrace.AntiFormat
in the stack trace suggests that someone is trying to print an error message to the trace output sink (typically the VS output window). Does this happen in .NET 5.0?A null-reference error suggests that the error message is null. This shouldn't happen, but perhaps something is wrong with your installation of .NET Framework, maybe the error message lookup fails because of a localization problem. A crash dump might shed light on this; the XAML and code-behind is definitely not enough.
I'm sorry that the original project can't be provided, but I'm trying to write a sample. Please wait me some days. Thanks.
The StackTrace is here
VS show error line
designUnits.Add(unit);//ERROR
designUnits
type is ObservableCollection<T>
, unit
is a normal clr object, but it contains a Bound instance and a UIElement properties.
VS Version VS 2019 Communtity 16.10.4
@Cricle Is it possible to provide the minimal repro?
@Cricle Is it possible to provide the minimal repro?
I'll try
OK so '{0}' (Name='{1}')
is only in TraceData.DescribeSourceObject
, which means that targetElement
is not null in DescribeTarget
and we know it's a FrameworkElement
otherwise DescribeSourceObject
would not try to print the Name string.
Now the next call is:
where
so either arg1
or arg2
is null
here.
arg1
is a type name which presumably is not null
, especially since it's a type deriving from FrameworkElement
.
Ergo the FrameworkElement
's Name
must be null
.
The purpose of AntiFormat
is to escape a string to be passed to the Format
method, so it should not be used on arguments, only the message. Plus, I think checking for and transparently passing null
is a good hygiene for any escaping/unescaping routine.
I found!!!
It will given null value!
The code
public class ASetting
{
public string Ax { get; set; }
}
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
var t = new TextBox();
var data = new ASetting();
//When I bind control name alway null
t.SetBinding(NameProperty, new Binding("Ax") { Source = data });
//I set an error binding, it must throw NullReferenceException
t.SetBinding(TextBox.AcceptsReturnProperty, new Binding
{
Source = data,
Path=new PropertyPath("aaa")
});
}
}
@singhashish-wpf @miloush @SamBent @lindexi
@Cricle Yes, I think it is the WPF bug. Thank you.
var t = new TextBox()
{
Name = null, // Set the Name to null
};
var data = new ASetting();
////When I bind control name alway null
////t.SetBinding(NameProperty, new Binding("Ax") { Source = data });
//I set an error binding, it must throw NullReferenceException
t.SetBinding(TextBox.AcceptsReturnProperty, new Binding
{
Source = data,
Path = new PropertyPath("aaa")
});
All the code : https://github.com/lindexi/lindexi_gd/tree/b89cee95091997cda801cf20f6042d30f7f85518/KedenejekiLallcallyine
Configuration
Problem
When I use background binding, provided
Path
,Source
and set modeTwoWay
, always throw NullReferenceException , but in net5.0 no exception, but how can i do when in NET Framework?Whether i use
SetBinding
orBindingOperations.SetBinding
.StackTrack
Code