I have a class that inherits from Grid, called MapGrid. MapGrid displays a MapView (implemented on both platforms), some labels, and a button.
To display this grid, the user launches the app, taps a button that opens a flyout menu, and then taps a button in the flyout menu. The flyout menu gets dismissed and this grid is displayed in a contentview that fills the screen.
I used Automator to run a loop of:
opening flyout menu > tapping menu option > waiting for the view > closing the view
for 10 minutes. One "loop" takes about 10 seconds (my computer is slow).
Sometimes during this loop, the app crashes with the following error:
An item with the same key has already been added. Key: Microsoft.Maui.Controls.BindableProperty
source: "System.Private.CoreLib"
stack trace:
at System.Collections.Generic.Dictionary`2[[Microsoft.Maui.Controls.BindableProperty, Microsoft.Maui.Controls, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Controls.BindableObject.BindablePropertyContext, Microsoft.Maui.Controls, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].TryInsert(BindableProperty key, BindablePropertyContext value, InsertionBehavior behavior)
at System.Collections.Generic.Dictionary`2[[Microsoft.Maui.Controls.BindableProperty, Microsoft.Maui.Controls, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Controls.BindableObject.BindablePropertyContext, Microsoft.Maui.Controls, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].Add(BindableProperty key, BindablePropertyContext value)
at Microsoft.Maui.Controls.BindableObject.SetValueCore(BindableProperty property, Object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes)
at Microsoft.Maui.Controls.MultiBinding.Apply(Boolean fromTarget)
at Microsoft.Maui.Controls.MultiBinding.OnBindingChanged(BindableObject bindable, Object oldValue, Object newValue)
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(Boolean fromTarget)
at Microsoft.Maui.Controls.BindingExpression.BindingExpressionPart.<PropertyChanged>b__49_0()
at Microsoft.Maui.Dispatching.Dispatcher.<>c__DisplayClass9_0.<DispatchImplementation>b__0()
at CoreFoundation.DispatchQueue.static_dispatcher_to_managed(IntPtr context)
at UIKit.UIApplication.UIApplicationMain(Int32 argc, String[] argv, IntPtr principalClassName, IntPtr delegateClassName)
at UIKit.UIApplication.Main(String[] args, Type principalClass, Type delegateClass)
at meescan.Platforms.IOS.Program.Main(String[] args) in /Users/eamonn.alphin/Documents/git/meescan/Platforms/iOS/Program.cs:line 14
Suspecting the issue is related to the mapview not being disposed, I call:
this.Unloaded += (s,e) =>{
this.Clear()
}
mapview.Unloaded += (s,e) =>{
mapView?.Handler?.DisconnectHandler();
}
but the issue still occurs. Sometimes it happens after 2 minutes, sometimes after 8. I use dynamic resources, but I have a check in place to catch any duplicate keys, so I don't think it's related to dynamic resources.
It also only occurs on this view, not on any classes called by it (like view model, or the class I use to generate the dynamic resources).
I tried googling for results, but I only get the obvious "I have a dictionary/collection/list...".
I'm using Net6.0, a 6.7in iOS simulator running iOS 16.0, on a Mac running Ventura, Visual Studio Preview 17.4 build 2326
Any ideas what might be causing this crash/error or how to debug it better?