maui: remove_RequestedThemeChanged cause null reference
Description
From our clients we periodically receiving System.NullReferenceException System.NullReferenceException: Object reference not set to an instance of an object.
Microsoft.Maui.WeakEventManager.RemoveEventHandler(String eventName, Object handlerTarget, MemberInfo methodInfo)
Microsoft.Maui.WeakEventManager.RemoveEventHandler[AppThemeChangedEventArgs](EventHandler1 handler, String eventName) Microsoft.Maui.Controls.Application.remove_RequestedThemeChanged(EventHandler1 value)
Microsoft.Maui.Controls.AppThemeBinding.SetAttached(Boolean value)
Microsoft.Maui.Controls.AppThemeBinding.Unapply(Boolean fromBindingContextChanged)
Microsoft.Maui.Controls.BindableObject.SetBinding(BindableProperty targetProperty, BindingBase binding, SetterSpecificity specificity)
Microsoft.Maui.Controls.Setter.Apply(BindableObject target, SetterSpecificity specificity)
Microsoft.Maui.Controls.Style.ApplyCore(BindableObject bindable, Style basedOn, SetterSpecificity specificity)
Microsoft.Maui.Controls.Style.Microsoft.Maui.Controls.IStyle.Apply(BindableObject bindable, SetterSpecificity specificity)
Microsoft.Maui.Controls.MergedStyle.SetStyle(IStyle implicitStyle, IList`1 classStyles, IStyle style)
Microsoft.Maui.Controls.MergedStyle.set_Style(IStyle value)
Microsoft.Maui.Controls.NavigableElement.<>c.<.cctor>b__22_0(BindableObject bindable, Object oldvalue, Object newvalue)
Microsoft.Maui.Controls.BindableObject.SetValueActual(BindableProperty property, BindablePropertyContext context, Object value, Boolean currentlyApplying, SetValueFlags attributes, SetterSpecificity specificity, Boolean silent)
Microsoft.Maui.Controls.BindableObject.SetValueCore(BindableProperty property, Object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes, SetterSpecificity specificity)
Microsoft.Maui.Controls.BindableObject.SetValue(BindableProperty property, Object value)
Microsoft.Maui.Controls.NavigableElement.set_Style(Style value)
Core.UI.Controls.CustomViews.CustomMessageBoxView.InitializeComponent()
Core.UI.Controls.CustomViews.CustomMessageBoxView…ctor()
Core.UI.CustomMessageBoxWrapper.ShowError(String title, String message, String errorButtonText, String iconSource)
Core.ExceptionHandler.<>c__DisplayClass1_0.<Handle>b__0()
Java.Lang.Thread.RunnableImplementor.Run()
Java.Lang.IRunnableInvoker.n_Run(IntPtr jnienv, IntPtr native__this)
Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PP_V(_JniMarshal_PP_V callback, IntPtr jnienv, IntPtr klazz)
Steps to Reproduce
No response
Link to public reproduction project repository
No response
Version with bug
8.0.6
Is this a regression from previous behavior?
Not sure, did not test other versions
Last version that worked well
Unknown/Other
Affected platforms
Android
Affected platform versions
No response
Did you find any workaround?
No response
Relevant log output
Microsoft.Maui.WeakEventManager.RemoveEventHandler(String eventName, Object handlerTarget, MemberInfo methodInfo)
Microsoft.Maui.WeakEventManager.RemoveEventHandler[AppThemeChangedEventArgs](EventHandler`1 handler, String eventName)
Microsoft.Maui.Controls.Application.remove_RequestedThemeChanged(EventHandler`1 value)
Microsoft.Maui.Controls.AppThemeBinding.SetAttached(Boolean value)
Microsoft.Maui.Controls.AppThemeBinding.Unapply(Boolean fromBindingContextChanged)
Microsoft.Maui.Controls.BindableObject.SetBinding(BindableProperty targetProperty, BindingBase binding, SetterSpecificity specificity)
Microsoft.Maui.Controls.Setter.Apply(BindableObject target, SetterSpecificity specificity)
Microsoft.Maui.Controls.Style.ApplyCore(BindableObject bindable, Style basedOn, SetterSpecificity specificity)
Microsoft.Maui.Controls.Style.Microsoft.Maui.Controls.IStyle.Apply(BindableObject bindable, SetterSpecificity specificity)
Microsoft.Maui.Controls.MergedStyle.SetStyle(IStyle implicitStyle, IList`1 classStyles, IStyle style)
Microsoft.Maui.Controls.MergedStyle.set_Style(IStyle value)
Microsoft.Maui.Controls.NavigableElement.<>c.<.cctor>b__22_0(BindableObject bindable, Object oldvalue, Object newvalue)
Microsoft.Maui.Controls.BindableObject.SetValueActual(BindableProperty property, BindablePropertyContext context, Object value, Boolean currentlyApplying, SetValueFlags attributes, SetterSpecificity specificity, Boolean silent)
Microsoft.Maui.Controls.BindableObject.SetValueCore(BindableProperty property, Object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes, SetterSpecificity specificity)
Microsoft.Maui.Controls.BindableObject.SetValue(BindableProperty property, Object value)
Microsoft.Maui.Controls.NavigableElement.set_Style(Style value)
Core.UI.Controls.CustomViews.CustomMessageBoxView.InitializeComponent()
Core.UI.Controls.CustomViews.CustomMessageBoxView..ctor()
Core.UI.CustomMessageBoxWrapper.ShowError(String title, String message, String errorButtonText, String iconSource)
Core.ExceptionHandler.<>c__DisplayClass1_0.<Handle>b__0()
Java.Lang.Thread.RunnableImplementor.Run()
Java.Lang.IRunnableInvoker.n_Run(IntPtr jnienv, IntPtr native__this)
Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PP_V(_JniMarshal_PP_V callback, IntPtr jnienv, IntPtr klazz)
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 2
- Comments: 21 (8 by maintainers)
@cytoph you must access UI elements in UI thread. So, you must call view.ScrollTo(index, groupIndex, position, animate) in UI thread.
You can wrap call to ScrollToAsync in InvokeOnMainThread (if UI is shown in MainThread )… var isScrolled = await MainThread.InvokeOnMainThreadAsync(() => ScrollToAsync(view, groupIndex, position, animate));