MapView ObjectDisposedException IOS

3105
9
Jump to solution
10-14-2020 05:40 AM
TomášZachoval
New Contributor III

Hello,

I'm using nuget Esri.ArcGISRuntime.Xamarin.Forms v. 100.9.0 on Android platform everything works fine, but on IOS i found bug which I was also able to reproduce in a clean project.

It is this exception:

Exception

- $exception {System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'MapView'.
at Foundation.NSObject.get_SuperHandle () [0x0004a] in /Library/Frameworks/Xamarin.iOS.framework/Versions/14.0.0.0/src/Xamarin.iOS/Foundation/NSObject2.cs:401
at UIKit.UIView.get_Bounds () [0x0009d] in /Library/Frameworks/Xamarin.iOS.framework/Versions/14.0.0.0/src/Xamarin.iOS/UIKit/UIView.g.cs:3114
at Esri.ArcGISRuntime.UI.Controls.GeoView.ApplicationDidBecomeActive (System.WeakReference`1 geoview) [0x0000d] in <feaa53e84d7043e88504283a2c404a62>:0
at Esri.ArcGISRuntime.UI.Controls.GeoView+<>c__DisplayClass47_0.<SetupApplicationNotificationHandlers>b__3 (System.Object s, Foundation.NSNotificationEventArgs e) [0x00000] in <feaa53e84d7043e88504283a2c404a62>:0
at UIKit.UIApplication+Notifications+<>c__DisplayClass4_0.<ObserveDidBecomeActive>b__0 (Foundation.NSNotification notification) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/14.0.0.0/src/Xamarin.iOS/UIKit/UIApplication.g.cs:2092
at Foundation.InternalNSNotificationHandler.Post (Foundation.NSNotification s) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/14.0.0.0/src/Xamarin.iOS/Foundation/NSNotificationCenter.cs:48
at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Library/Frameworks/Xamarin.iOS.framework/Versions/14.0.0.0/src/Xamarin.iOS/UIKit/UIApplication.cs:86
at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0000e] in /Library/Frameworks/Xamarin.iOS.framework/Versions/14.0.0.0/src/Xamarin.iOS/UIKit/UIApplication.cs:65
at Ag.App.Phone.Ios.Application.Main (System.String[] args) [0x00001] in C:\devel\App\Source\App.Phone.iOS\Main

- $exception {System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'MapView'.
at Foundation.NSObject.get_SuperHandle () [0x0004a] in /Library/Frameworks/Xamarin.iOS.framework/Versions/14.0.0.0/src/Xamarin.iOS/Foundation/NSObject2.cs:401
at UIKit.UIView.get_Bounds () [0x0009d] in /Library/Frameworks/Xamarin.iOS.framework/Versions/14.0.0.0/src/Xamarin.iOS/UIKit/UIView.g.cs:3114
at Esri.ArcGISRuntime.UI.Controls.GeoView.ApplicationDidBecomeActive (System.WeakReference`1 geoview) [0x0000d] in <feaa53e84d7043e88504283a2c404a62>:0
at Esri.ArcGISRuntime.UI.Controls.GeoView+<>c__DisplayClass47_0.<SetupApplicationNotificationHandlers>b__3 (System.Object s, Foundation.NSNotificationEventArgs e) [0x00000] in <feaa53e84d7043e88504283a2c404a62>:0
at UIKit.UIApplication+Notifications+<>c__DisplayClass4_0.<ObserveDidBecomeActive>b__0 (Foundation.NSNotification notification) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/14.0.0.0/src/Xamarin.iOS/UIKit/UIApplication.g.cs:2092
at Foundation.InternalNSNotificationHandler.Post (Foundation.NSNotification s) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/14.0.0.0/src/Xamarin.iOS/Foundation/NSNotificationCenter.cs:48
at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Library/Frameworks/Xamarin.iOS.framework/Versions/14.0.0.0/src/Xamarin.iOS/UIKit/UIApplication.cs:86
at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0000e] in /Library/Frameworks/Xamarin.iOS.framework/Versions/14.0.0.0/src/Xamarin.iOS/UIKit/UIApplication.cs:65
at Ag.App.Phone.Ios.Application.Main (System.String[] args) [0x00001] in C:\devel\App\Source\App.Phone.iOS\Main.cs:12 } System.ObjectDisposedException

Exception appearing alwayse when i have loaded MapView on current page. Then I go to another page. Then send app to background. Do work and return back to the app. And when app is send from backgroud to foreground it will crash on System.ObjectDisposedException: Cannot access a disposed object.Object name: 'MapView' . On physical device it happen almost everytime on simulator sometimes not.

If I send app to backgroud and current page is page with MapView it works fine. 

Example in suffix. 

Thanks for your help

T. Zachoval

 

0 Kudos
1 Solution

Accepted Solutions
JohannesHoerhan
New Contributor

Hi Tomáš

I have exactly the same symtoms with my iOS app. Fixed it with a custom renderer for MapView:

[assembly: ExportRenderer(typeof(Esri.ArcGISRuntime.Xamarin.Forms.MapView), typeof(MyMapViewRenderer))]

namespace xxx.Forms.iOS
{
public class MyMapViewRenderer : MapViewRenderer 
{

protected override bool ManageNativeControlLifetime => false;
}
}

This is enough to make my app work as expected! Maybe this can help you too.

regards,

Hannes

View solution in original post

9 Replies
JohannesHoerhan
New Contributor

Hi Tomáš

I have exactly the same symtoms with my iOS app. Fixed it with a custom renderer for MapView:

[assembly: ExportRenderer(typeof(Esri.ArcGISRuntime.Xamarin.Forms.MapView), typeof(MyMapViewRenderer))]

namespace xxx.Forms.iOS
{
public class MyMapViewRenderer : MapViewRenderer 
{

protected override bool ManageNativeControlLifetime => false;
}
}

This is enough to make my app work as expected! Maybe this can help you too.

regards,

Hannes

TomášZachoval
New Contributor III

Hello, Johannes

Your solution works amazing, I am really grateful. Thank you so much for your help. 

I wish you happy coding.

Tomas

0 Kudos
GlobeRider
New Contributor

Hi- Can you share how you implemented your custom renderer? I've been scratching my head for an hour or two.  

0 Kudos
dotMorten_esri
Esri Notable Contributor

Thank you for the sample app. 
I've been trying to reproduce this with the above provided app. The about page is binding to a Map in the AbouveViewModel, but that property doesn't seem to exist. I added it, so I get a map, and tried navigating around, but not getting the crash.

Do you have an updated sample app with some specific repro steps that demonstrates the problem?

Also we did do some fixes in Update 10, especially around ensuring null-checks, so there's a good chance this issue has been resolved. However I'd like to try and repro in Update 9, just to make sure.

Thanks

0 Kudos
dotMorten_esri
Esri Notable Contributor

...actually ignore that. I was finally able to reproduce in update 9 and 10.

0 Kudos
GlobeRider
New Contributor

Hi- I'm able to reproduce using MapView, SceneView and ARSceneView.  I've tried adding the map views programmatically and removing them when the OnDisappering event fires, but it still throws an error when navigating away from a page that uses a MapView.  I've tried opening as a "modal" and it still crashes it.  So, it's seems to be a pretty serious bug (for me at least).

 

Steps to reproduce:

1. Open Page with MapView, SceneView or ARSceneView. 

2. Go Back or Close Page

3. Open Another App on Phone. (i.e. Send MapApp to Background)

4. Re-Open MapApp

5. Crash       

Runtime 100.10.0

0 Kudos
RickBobbitt
New Contributor

Any updates to a fix? I am getting this also in 100.10.

0 Kudos
JeremyBridges
Occasional Contributor

We've run into this issue ourselves. We'll try the work-around and look forward to a fix in the Runtime.

System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'MapView'.**

**Stack trace**:

- at Foundation.NSObject.get_SuperHandle ()
- at UIKit.UIView.get_Bounds ()
- at Esri.ArcGISRuntime.UI.Controls.GeoView.ApplicationDidBecomeActive (System.WeakReference<T>[T] geoview)
- at Esri.ArcGISRuntime.UI.Controls.GeoView+<>c__DisplayClass47_0.<SetupApplicationNotificationHandlers>b__3 (System.Object s, Foundation.NSNotificationEventArgs e)
- at UIKit.UIApplication+Notifications+<>c__DisplayClass4_0.<ObserveDidBecomeActive>b__0 (Foundation.NSNotification notification)
- at Foundation.InternalNSNotificationHandler.Post (Foundation.NSNotification s)
- at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
- at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate)
- at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName)

0 Kudos
dotMorten_esri
Esri Notable Contributor

Just to follow up on this. We'll have a fix for this in Update 11. The above proposed workaround with a renderer is a good way to do it for now - the only downside might be that if you create A LOT of MapView instances, it might leak a bit of memory, but if you're not you should be fine.