question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Two ways binding NullReferenceException

See original GitHub issue

Configuration

Name Version
dotnet tool 5.0.302
target framework net452, net461, net472

Problem

When I use background binding, provided Path, Source and set mode TwoWay, always throw NullReferenceException , but in net5.0 no exception, but how can i do when in NET Framework?

Whether i use SetBinding or BindingOperations.SetBinding.

StackTrack

   at MS.Internal.AvTrace.AntiFormat(String s)
1

Code

var q = new Binding();
q.Path = new PropertyPath("RotateTransform");
q.Source = obj.RotateTransformDesigner;
q.Mode = BindingMode.TwoWay;
Bd.SetBinding(Control.RenderTransformProperty, q);
BindingOperations.SetBinding(Bd, Control.RenderTransformProperty, q);//ERROR

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
Criclecommented, Jul 2, 2022

image I found!!!

image 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

1reaction
Criclecommented, Aug 12, 2021

@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

1

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

wpf - TwoWay mode binding scenario for null or empty data ...
The behavior of the string type seems fine to me. Two way binding means that the value in the textbox reflects the value...
Read more >
Two-way binding not work with non-null assertion operator
But when I add a non-null assertion operator to the two-way binding value, the compilation result does not meet expectations.
Read more >
2way binding on input but still show if null : r/Angular2
Say I have a 2 way binding like this: <input id="account-input-number" type="tel" [(ngModel)]="selectedAccount.username"/>.
Read more >
Binding.TargetNullValue Property (Windows.UI.Xaml.Data)
TargetNullValue might be used for bindings that bind a collection and the source data uses null for missing info only in some of...
Read more >
ASP.NET Core Blazor data binding
Two -way binding to a property with get / set accessors requires discarding the Task returned by EventCallback.InvokeAsync. For two-way data ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found