NullReferenceException at BindingExpression
- Dominant language
- C#
- Stars
- 23.3k
- Forks
- 2k
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 290
Description
### Description
In app log:
`System.NullReferenceException:Object reference not set to an instance of an object at Microsoft.Maui.Controls.WeakEventProxy`2[[System.ComponentModel.INotifyPropertyChanged, System.ObjectModel, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a],[System.ComponentModel.PropertyChangedEventHandler, System.ObjectModel, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]].TryGetHandler(PropertyChangedEventHandler& )
at Microsoft.Maui.Controls.BindingExpression.WeakPropertyChangedProxy.OnPropertyChanged(Object sender, PropertyChangedEventArgs e)
at SomeViewModel.SomeProperty.OnPropertyChanged(String propertyName)`
could be race condition in _expression.Apply() (Dispatcher.Dispatch)
[https://github.com/dotnet/maui/blob/bf96ba698d8abb3b5b69396c905abc0078280b20/src/Controls/src/Core/BindingExpression.cs#L713](url)
possible fix=> obj.Dispatcher.DispatchIfRequired(() => _expression?.Apply());
### Steps to Reproduce
_No response_
### Link to public reproduction project repository
_No response_
### Version with bug
9.0.110 SR12
### Is this a regression from previous behavior?
Not sure, did not test other versions
### Last version that worked well
_No response_
### Affected platforms
Android
### Affected platform versions
_No response_
### Did you find any workaround?
trying to update bound properties on the UI thread.
### Relevant log output
```shell
```
Contributor guide
Research direction
Start by reading src/Controls/src/Core/BindingExpression.cs around line 713 and trace the WeakEventProxy`2.TryGetHandler call shown in the Android stack trace. Establish a reproducible Android case involving updates from SomeViewModel.SomeProperty, then verify the NullReferenceException no longer occurs under the reported threading conditions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, csharp
- Domain
- mobile-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100