MemoryToolkit.Maui icon indicating copy to clipboard operation
MemoryToolkit.Maui copied to clipboard

Try/Catch Needed in DisconnectImpl()

Open bsloehr opened this issue 10 months ago • 0 comments

Needed to add a try/catch around certain calls within DisconnectImpl(). The offending culprit in this case is the SyncFusion ListView control. The exception shows a NullReferenceException happening deep in their code. I'll report this to SyncFusion as well.

04-22 18:43:17.661 [-DBG-1] TrySafe:Exception in DisconnectImpl (Disconnect Handler Syncfusion.Maui.ListView.ListViewEmptyViewItem): System.NullReferenceException: Object reference not set to an instance of an object.
   at Syncfusion.Maui.ListView.ListViewItemExtensions.WireEvents(ListViewItem listViewItem)
   at Syncfusion.Maui.ListView.ListViewItem.OnHandlerChanged()
   at Microsoft.Maui.Controls.VisualElement.OnHandlerChangedCore()
   at Microsoft.Maui.Controls.Element.SetHandler(IElementHandler newHandler)
   at Microsoft.Maui.Handlers.ElementHandler.DisconnectHandler(Object platformView)
   at Microsoft.Maui.Handlers.ElementHandler.Microsoft.Maui.IElementHandler.DisconnectHandler()
   at Mobile.Framework.NavigatorUtilities.<>c__DisplayClass0_0.<Disconnect>b__7()
   at Mobile.Framework.NavigatorUtilities.<Disconnect>g__TrySafely|0_0(Action action, String msg) 
        void TrySafely(Action action, string? msg = null)
        {
            try { action.Invoke();} catch (Exception e)
            {
                Serilog.Log.Logger.Verbose($"TrySafe:Exception in DisconnectImpl ({msg}): {e}");
            }
        }
TrySafely(() => { visualElement.Handler?.DisconnectHandler(); }, $"Disconnect Handler {visualElement}");

bsloehr avatar Apr 23 '24 00:04 bsloehr