BoldDeskWe are launching BoldDesk on Product Hunt soon. Learn more & follow us.
SfDataGrid - Updating MVVM (INotifyPropertyChanged) Properties of List members from a Task cause exception
Tested with Windows and MacOSX, example attached.
Message
UIKit Consistency error: you are calling a UIKit method that can only be invoked from the UI thread.
StackTrace:
at UIKit.UIApplication.EnsureUIThread()
at UIKit.UILabel.set_Text(String value)
at Microsoft.Maui.Controls.Platform.LabelExtensions.UpdateText(UILabel platformLabel, Label label)
at Microsoft.Maui.Controls.Label.MapText(ILabelHandler handler, Label label)
at Microsoft.Maui.Controls.Label.MapText(LabelHandler handler, Label label)
at Microsoft.Maui.PropertyMapper`2.<>c__DisplayClass5_0[[Microsoft.Maui.Controls.Label, Microsoft.Maui.Controls, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Handlers.LabelHandler, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].<Add>b__0(IElementHandler h, IElement v)
at Microsoft.Maui.PropertyMapper.UpdatePropertyCore(String key, IElementHandler viewHandler, IElement virtualView)
at Microsoft.Maui.PropertyMapper.UpdateProperty(IElementHandler viewHandler, IElement virtualView, String property)
at Microsoft.Maui.Handlers.ElementHandler.UpdateValue(String property)
at Microsoft.Maui.Controls.Element.OnPropertyChanged(String propertyName)
at Microsoft.Maui.Controls.BindableObject.SetValueActual(BindableProperty property, BindablePropertyContext context, Object value, Boolean currentlyApplying, SetValueFlags attributes, Boolean silent)
at Microsoft.Maui.Controls.BindableObject.SetValueCore(BindableProperty property, Object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes)
at Microsoft.Maui.Controls.BindingExpression.ApplyCore(Object sourceObject, BindableObject target, BindableProperty property, Boolean fromTarget)
at Microsoft.Maui.Controls.BindingExpression.Apply(Object sourceObject, BindableObject target, BindableProperty property)
at Microsoft.Maui.Controls.Binding.Apply(Object context, BindableObject bindObj, BindableProperty targetProperty, Boolean fromBindingContextChanged)
at Microsoft.Maui.Controls.BindableObject.SetBinding(BindableProperty targetProperty, BindingBase binding, Boolean fromStyle)
at Microsoft.Maui.Controls.BindableObject.SetBinding(BindableProperty targetProperty, BindingBase binding)
at Syncfusion.Maui.DataGrid.DataGridCellRenderer`2[[Microsoft.Maui.Controls.Label, Microsoft.Maui.Controls, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Controls.View, Microsoft.Maui.Controls, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].OnInitializeDisplayView(DataColumnBase dataColumn, Label view)
at Syncfusion.Maui.DataGrid.DataGridCellRenderer`2[[Microsoft.Maui.Controls.Label, Microsoft.Maui.Controls, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Controls.View, Microsoft.Maui.Controls, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].OnUpdateDisplayValue(DataColumnBase dataColumn, Label view)
at Syncfusion.Maui.DataGrid.DataGridCellRenderer`2[[Microsoft.Maui.Controls.Label, Microsoft.Maui.Controls, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Controls.View, Microsoft.Maui.Controls, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].OnRefreshDisplayValue(DataColumnBase dataColumn)
at Syncfusion.Maui.DataGrid.DataGridCellRenderer`2[[Microsoft.Maui.Controls.Label, Microsoft.Maui.Controls, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Controls.View, Microsoft.Maui.Controls, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].RefreshDisplayValue(DataColumnBase dataColumn)
at Syncfusion.Maui.DataGrid.GridModel.<>c__DisplayClass29_0.<OnRecordPropertyChanged>b__2(DataColumnBase datacol)
at Syncfusion.Maui.Data.FunctionalExtensions.ForEach[DataColumnBase](IEnumerable`1 items, Action`1 action)
at Syncfusion.Maui.DataGrid.GridModel.OnRecordPropertyChanged(Object sender, PropertyChangedEventArgs e)
at Syncfusion.Maui.Data.CollectionViewAdv.OnRecordPropertyChanged(Object sender, PropertyChangedEventArgs e)
at Syncfusion.Maui.Data.CollectionViewAdv.OnPropertyChanged(Object sender, PropertyChangedEventArgs e)
at MacGridTest.Data.GridData.OnPropertyChanged(PropertyChangedEventArgs e) in /Users/user/Projects/Tests/MacGridTest/CommunityToolkit.Mvvm.SourceGenerators/CommunityToolkit.Mvvm.SourceGenerators.INotifyPropertyChangedGenerator/MacGridTest.Data.GridData.g.cs:line 20
at MacGridTest.Data.GridData.set_String1(String value) in /Users/user/Projects/Tests/MacGridTest/CommunityToolkit.Mvvm.SourceGenerators/CommunityToolkit.Mvvm.SourceGenerators.ObservablePropertyGenerator/MacGridTest.Data.GridData.g.cs:line 93
at MacGridTest.Pages.SfGridPageViewmodel.<RunBgTaskl>b__2_0() in /Users/user/Projects/Tests/MacGridTest/Pages/SfGridPageViewmodel.cs:line 29
[RelayCommand] private void RunBgTaskl() { MainThread.BeginInvokeOnMainThread(async () => { try { System.Diagnostics.Debug.WriteLine("Task started."); await Task.Delay(1000); foreach (var item in list) { item.String1 = $"{item.Iteration} string."; System.Diagnostics.Debug.WriteLine($"changed item with id {item.Id}."); await Task.Delay(500); } } catch(Exception ex) { System.Diagnostics.Debug.WriteLine($"error: {ex.Message}"); } }); } |
No that issues also occures on Windows as writtin in my inital post:
at WinRT.ExceptionHelpers.g__Throw|20_0(Int32 hr)
at ABI.Microsoft.UI.Xaml.Controls.ITextBlockMethods.set_Text(IObjectReference _obj, String value)
at Microsoft.Maui.Controls.Element.OnPropertyChanged(String propertyName)
at Microsoft.Maui.Controls.BindableObject.SetValueActual(BindableProperty property, BindablePropertyContext context, Object value, Boolean currentlyApplying, SetValueFlags attributes, Boolean silent)
at Microsoft.Maui.Controls.BindableObject.SetValueCore(BindableProperty property, Object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes)
at Microsoft.Maui.Controls.BindingExpression.ApplyCore(Object sourceObject, BindableObject target, BindableProperty property, Boolean fromTarget)
at Microsoft.Maui.Controls.BindingExpression.Apply(Object sourceObject, BindableObject target, BindableProperty property)
at Microsoft.Maui.Controls.Binding.Apply(Object context, BindableObject bindObj, BindableProperty targetProperty, Boolean fromBindingContextChanged)
at Microsoft.Maui.Controls.BindableObject.SetBinding(BindableProperty targetProperty, BindingBase binding, Boolean fromStyle)
at Syncfusion.Maui.DataGrid.DataGridCellRenderer`2.OnInitializeDisplayView(DataColumnBase dataColumn, T1 view)
at Syncfusion.Maui.DataGrid.DataGridCellRenderer`2.OnUpdateDisplayValue(DataColumnBase dataColumn, T1 view)
at Syncfusion.Maui.DataGrid.DataGridCellRenderer`2.OnRefreshDisplayValue(DataColumnBase dataColumn)
at Syncfusion.Maui.DataGrid.DataGridCellRenderer`2.RefreshDisplayValue(DataColumnBase dataColumn)
at Syncfusion.Maui.DataGrid.GridModel.<>c__DisplayClass29_0.b__2(DataColumnBase datacol)
at Syncfusion.Maui.Data.FunctionalExtensions.ForEach[T](IEnumerable`1 items, Action`1 action)
at Syncfusion.Maui.DataGrid.GridModel.OnRecordPropertyChanged(Object sender, PropertyChangedEventArgs e)
at Syncfusion.Maui.Data.CollectionViewAdv.OnRecordPropertyChanged(Object sender, PropertyChangedEventArgs e)
at Syncfusion.Maui.Data.CollectionViewAdv.OnPropertyChanged(Object sender, PropertyChangedEventArgs e)
at MacGridTest.Data.GridData.OnPropertyChanged(PropertyChangedEventArgs e) in C:\repos\Tests\MacGridTest\CommunityToolkit.Mvvm.SourceGenerators\CommunityToolkit.Mvvm.SourceGenerators.INotifyPropertyChangedGenerator\MacGridTest.Data.GridData.g.cs:line 20
If i just have the same values bound to a normal Lable or a Label in a SfListView Item Template, etc. it is working.
also the Task is and the Model Objects is comming form a SharedLibrary that has no access to use
MainThread.BeginInvokeOnMainThread
({});
As this example is ony a simplified example
Hi Andreas,
We have logged bug report for the reported issue "Exception thrown when underlying property value changed using Task.Run". We will fix the issue and include the fix in our upcoming weekly nuget release which is scheduled on 3rdJan 2023.
You can track the status of this report through the following feedback link,
We have fixed the reported issue “Exception thrown when underlying property value changed using Task.Run” and included the issue fix in our latest NuGet release update version 20.4.0.42 which is available for download (https://www.nuget.org/).
We thank you for your support and appreciate your patience in waiting for this update. Please get in touch with us if you require any further assistance.