0

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?

  • While it is good to *describe* what your code does, it is important to add to question the **code** itself. Add code for *"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."* ALSO, please verify that you can get it to crash manually, doing those user actions repeatedly. To eliminate the possibility that Automator is somehow an issue with Maui. – ToolmakerSteve Oct 27 '22 at 22:56
  • **1)** I see *"MultiBinding.OnBindingChanged"* in that call stack. Is there a MultiBinding in your xaml/c#? **2)** Comment out various parts of your xaml/c#, to isolate the problem. For example, replace mapview with some simple view (perhaps a contentview). Still happen? – ToolmakerSteve Oct 27 '22 at 23:06
  • @ToolmakerSteve I WISH I could get it to crash predictably. I'm only using automator to do the same 3 button clicks that I would do, rather than sit there myself for 10 minutes. Yes, there is a multi binding that combines a bool and two colours and uses the boolean to determine which color to set. I'm working now on commenting out various parts to see what might be happening. because this is work for my employer, I can't post the code without obfuscating a bunch of properties and names though, and then I'd have to provide all the related classes and it'd just be too much for the post. :( – EamonnA Oct 28 '22 at 17:00
  • @ToolmakerSteve so it crashed as it tried to add the label that uses the multi binding, I think you were on to something. – EamonnA Oct 28 '22 at 17:07

0 Answers0