Xamarin.forms: [Bug] [CustomRenderer] [iOS] Crash when navigating back from page with custom renderer control

Created on 31 May 2019  路  11Comments  路  Source: xamarin/Xamarin.Forms

Description

When I navigate back from page with custom renderer crash occurs.
Custom renderer is created using pattern from documentation: https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/custom-renderer/view

Steps to Reproduce

  1. Open my app
  2. Click on labeled button "Click me"
  3. Go back
  4. Crash occurs.

Code to reproduce:

In Shared project:

namespace CustomRendererTest
{
    public class CustomView : View
    {
    }

    public class App : Application
    {
        public App()
        {
            var rootPage = new ContentPage();
            var navigationPage = new NavigationPage(rootPage);
            var button = new Button()
            {
                Text = "Click me",
                Command = new Command(() => navigationPage.PushAsync(new ContentPage()
                {
                    Content = new CustomView()
                }))
            };
            var content = new StackLayout();
            content.Children.Add(button);
            content.Children.Add(new CustomView());
            rootPage.Content = content;
            this.MainPage = navigationPage;
        }
    }
}

in iOS project:

[assembly: ExportRenderer(typeof(CustomView), typeof(CustomRenderer))]
namespace CustomRendererTest.iOS
{
    public class CustomRenderer : ViewRenderer<CustomView, UIView>
    {
        protected override void OnElementChanged(ElementChangedEventArgs<CustomView> e)
        {
            base.OnElementChanged(e);

            //Pattern taken from: https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/custom-renderer/view
            if (this.Control == null)
            {
                // Instantiate the native control and assign it to the Control property with
                // the SetNativeControl method
                UIView myView = new UIView();
                this.SetNativeControl(myView);
            }

            if (e.OldElement != null)
            {
                // Unsubscribe from event handlers and cleanup any resources
            }

            if (e.NewElement != null)
            {
                // Configure the control and subscribe to event handlers
            }
        }
    }
}

Expected Behavior

No crash at navigating back from page

Actual Behavior

Crash big as hell

Basic Information

  • Version with issue: Xamarin.Forms 4.0.0.425677
  • Last known good version: Works good on Xamarin.Forms 3.5.0.274416
  • IDE: VS Professional 15.9.11
  • Platform Target Frameworks:

    • iOS: 12.2

  • Nuget Packages: Xamarin.Forms 4.0.0.425677
  • Affected Devices: all apple devices

Call Stack

System.NullReferenceException: Object reference not set to an instance of an object

2019-05-31 11:07:01.516588+0200 CustomRendererTest.iOS[77822:2556149] 
Unhandled Exception:
System.NullReferenceException: Object reference not set to an instance of an object
  at Xamarin.Forms.Platform.iOS.ViewRenderer`2[TView,TNativeView].SetNativeControl (TNativeView uiview) [0x0003b] in D:\a\1\s\Xamarin.Forms.Platform.iOS\ViewRenderer.cs:227 
  at CustomRendererTest.iOS.CustomRenderer.OnElementChanged (Xamarin.Forms.Platform.iOS.ElementChangedEventArgs`1[TElement] e) [0x0001d] in C:\Users\PawelK.INSYS\Desktop\CustomRendererTest\CustomRendererTest\CustomRendererTest.iOS\CustomRenderer.cs:22 
  at Xamarin.Forms.Platform.iOS.VisualElementRenderer`1[TElement].SetElement (TElement element) [0x00122] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementRenderer.cs:277 
  at Xamarin.Forms.Platform.iOS.VisualElementRenderer`1[TElement].Dispose (System.Boolean disposing) [0x0008c] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementRenderer.cs:358 
  at Xamarin.Forms.Platform.iOS.ViewRenderer`2[TView,TNativeView].
Dispose (System.Boolean disposing) [0x0005c] in D:\a\1\s\Xamarin.Forms.Platform.iOS\ViewRenderer.cs:124 
  at Foundation.NSObject.Dispose () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.4.0.64/src/Xamarin.iOS/Foundation/NSObject2.cs:147 
  at Xamarin.Forms.Platform.iOS.DisposeHelpers.DisposeModalAndChildRenderers (Xamarin.Forms.Element view) [0x00041] in D:\a\1\s\Xamarin.Forms.Platform.iOS\DisposeHelpers.cs:23 
  at Xamarin.Forms.Platform.iOS.Platform.HandleChildRemoved (System.Object sender, Xamarin.Forms.ElementEventArgs e) [0x00006] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Platform.cs:332 
  at Xamarin.Forms.Element.OnDescendantRemoved (Xamarin.Forms.Element child) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Element.cs:619 
  at Xamarin.Forms.Element.OnChildRemoved (Xamarin.Forms.Element child) [0x0001f] in D:\a\1\s\Xamarin.Forms.Core\Element.cs:339 
  at Xamarin.Forms.VisualElement.OnChildRemoved (Xamarin.Forms.Element child) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:750 
  at Xamarin.Forms.Page.OnInternalRemoved (Xamarin.Forms.VisualElement view) [0x00013] in D:\a\1\s\Xamarin.Forms.Core\Page.cs:433 
  at Xamarin.Forms.Page.InternalChildrenOnCollectionChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x0002c] in D:\a\1\s\Xamarin.Forms.Core\Page.cs:403 
  at System.Collections.ObjectModel.ObservableCollection`1[T].OnCollectionChanged (System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x00018] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.4.0.64/src/Xamarin.iOS/external/corefx/src/System.ObjectModel/src/System/Collections/ObjectModel/ObservableCollection.cs:263 
  at System.Collections.ObjectModel.ObservableCollection`1[T].OnCollectionChanged (System.Collections.Specialized.NotifyCollectionChangedAction action, System.Object item, System.Int32 index) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.4.0.64/src/Xamarin.iOS/external/corefx/src/System.ObjectModel/src/System/Collections/Ob
jectModel/ObservableCollection.cs:338 
  at System.Collections.ObjectModel.ObservableCollection`1[T].RemoveItem (System.Int32 index) [0x00021] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.4.0.64/src/Xamarin.iOS/external/corefx/src/System.ObjectModel/src/System/Collections/ObjectModel/ObservableCollection.cs:182 
  at System.Collections.ObjectModel.Collection`1[T].Remove (T item) [0x00027] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.4.0.64/src/Xamarin.iOS/external/corefx/src/Common/src/CoreLib/System/Collections/ObjectModel/Collection.cs:130 
  at Xamarin.Forms.NavigationPage+<Xamarin-Forms-INavigationPageController-RemoveAsyncInner>d__72.MoveNext () [0x000e7] in D:\a\1\s\Xamarin.Forms.Core\NavigationPage.cs:334 
--- End of stack trace from previous location where exception was thrown ---
  at Xamarin.Forms.Platform.iOS.NavigationRenderer+<UpdateFormsInnerNavigation>d__75.MoveNext () [0x00072] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Renderers\NavigationRenderer.cs:733 
--- End of stack 
trace from previous location where exception was thrown ---
  at Xamarin.Forms.Platform.iOS.NavigationRenderer+ParentingViewController+<DidMoveToParentViewController>d__41.MoveNext () [0x0003a] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Renderers\NavigationRenderer.cs:1292 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__6_0 (System.Object state) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.4.0.64/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1023 
  at Foundation.NSAsyncSynchronizationContextDispatcher.Apply () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.4.0.64/src/Xamarin.iOS/Foundation/NSAction.cs:178 
--- End of stack trace from previous location where exception was thrown ---
  at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
  at UIKit.UIApplication.Ma
in (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.4.0.64/src/Xamarin.iOS/UIKit/UIApplication.cs:79 
  at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0002c] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.4.0.64/src/Xamarin.iOS/UIKit/UIApplication.cs:63 
  at CustomRendererTest.iOS.Application.Main (System.String[] args) [0x00001] in C:\Users\PawelK.INSYS\Desktop\CustomRendererTest\CustomRendererTest\CustomRendererTest.iOS\Main.cs:17
2019-05-31 11:07:01.518317+0200 CustomRendererTest.iOS[77822:2556149] Unhandled managed exception:
Object reference not set to an instance of an object (System.NullReferenceException)
  at Xamarin.Forms.Platform.iOS.ViewRenderer`2[TView,TNativeView].SetNativeControl (TNativeView uiview) [0x0003b] in D:\a\1\s\Xamarin.Forms.Platform.iOS\ViewRenderer.cs:227 
  at CustomRendererTest.iOS.CustomRenderer.OnElementCh
anged (Xamarin.Forms.Platform.iOS.ElementChangedEventArgs`1[TElement] e) [0x0001d] in C:\Users\PawelK.INSYS\Desktop\CustomRendererTest\CustomRendererTest\CustomRendererTest.iOS\CustomRenderer.cs:22 
  at Xamarin.Forms.Platform.iOS.VisualElementRenderer`1[TElement].SetElement (TElement element) [0x00122] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementRenderer.cs:277 
  at Xamarin.Forms.Platform.iOS.VisualElementRenderer`1[TElement].Dispose (System.Boolean disposing) [0x0008c] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementRenderer.cs:358 
  at Xamarin.Forms.Platform.iOS.ViewRenderer`2[TView,TNativeView].Dispose (System.Boolean disposing) [0x0005c] in D:\a\1\s\Xamarin.Forms.Platform.iOS\ViewRenderer.cs:124 
  at Foundation.NSObject.Dispose () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.4.0.64/src/Xamarin.iOS/Foundation/NSObject2.cs:147 
  at Xamarin.Forms.Platform.iOS.DisposeHelpers.DisposeModalAndChildRenderers (Xamarin.Forms.Element view) [0x00041] in D:\a\1\s\Xamarin.Forms.Pl
atform.iOS\DisposeHelpers.cs:23 
  at Xamarin.Forms.Platform.iOS.Platform.HandleChildRemoved (System.Object sender, Xamarin.Forms.ElementEventArgs e) [0x00006] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Platform.cs:332 
  at Xamarin.Forms.Element.OnDescendantRemoved (Xamarin.Forms.Element child) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Element.cs:619 
  at Xamarin.Forms.Element.OnChildRemoved (Xamarin.Forms.Element child) [0x0001f] in D:\a\1\s\Xamarin.Forms.Core\Element.cs:339 
  at Xamarin.Forms.VisualElement.OnChildRemoved (Xamarin.Forms.Element child) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:750 
  at Xamarin.Forms.Page.OnInternalRemoved (Xamarin.Forms.VisualElement view) [0x00013] in D:\a\1\s\Xamarin.Forms.Core\Page.cs:433 
  at Xamarin.Forms.Page.InternalChildrenOnCollectionChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x0002c] in D:\a\1\s\Xamarin.Forms.Core\Page.cs:403 
  at System.Collections.ObjectModel.ObservableCollection`1[T].OnColle
ctionChanged (System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x00018] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.4.0.64/src/Xamarin.iOS/external/corefx/src/System.ObjectModel/src/System/Collections/ObjectModel/ObservableCollection.cs:263 
  at System.Collections.ObjectModel.ObservableCollection`1[T].OnCollectionChanged (System.Collections.Specialized.NotifyCollectionChangedAction action, System.Object item, System.Int32 index) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.4.0.64/src/Xamarin.iOS/external/corefx/src/System.ObjectModel/src/System/Collections/ObjectModel/ObservableCollection.cs:338 
  at System.Collections.ObjectModel.ObservableCollection`1[T].RemoveItem (System.Int32 index) [0x00021] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.4.0.64/src/Xamarin.iOS/external/corefx/src/System.ObjectModel/src/System/Collections/ObjectModel/ObservableCollection.cs:182 
  at System.Collections.ObjectModel.Collection`1[T].Remove (T item) [0x00027] 
in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.4.0.64/src/Xamarin.iOS/external/corefx/src/Common/src/CoreLib/System/Collections/ObjectModel/Collection.cs:130 
  at Xamarin.Forms.NavigationPage+<Xamarin-Forms-INavigationPageController-RemoveAsyncInner>d__72.MoveNext () [0x000e7] in D:\a\1\s\Xamarin.Forms.Core\NavigationPage.cs:334 
--- End of stack trace from previous location where exception was thrown ---
  at Xamarin.Forms.Platform.iOS.NavigationRenderer+<UpdateFormsInnerNavigation>d__75.MoveNext () [0x00072] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Renderers\NavigationRenderer.cs:733 
--- End of stack trace from previous location where exception was thrown ---
  at Xamarin.Forms.Platform.iOS.NavigationRenderer+ParentingViewController+<DidMoveToParentViewController>d__41.MoveNext () [0x0003a] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Renderers\NavigationRenderer.cs:1292 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.CompilerServices.AsyncMethodBuilderC
ore+<>c.<ThrowAsync>b__6_0 (System.Object state) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.4.0.64/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1023 
  at Foundation.NSAsyncSynchronizationContextDispatcher.Apply () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.4.0.64/src/Xamarin.iOS/Foundation/NSAction.cs:178 
--- End of stack trace from previous location where exception was thrown ---
  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/12.4.0.64/src/Xamarin.iOS/UIKit/UIApplication.cs:79 
  at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0002c] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.4.0.64/src/Xamarin.iOS/UI
Kit/UIApplication.cs:63 
  at CustomRendererTest.iOS.Application.Main (System.String[] args) [0x00001] in C:\Users\PawelK.INSYS\Desktop\CustomRendererTest\CustomRendererTest\CustomRendererTest.iOS\Main.cs:17
2019-05-31 11:07:01.518891+0200 CustomRendererTest.iOS[77822:2556149] critical: Stacktrace:
2019-05-31 11:07:01.519018+0200 CustomRendererTest.iOS[77822:2556149] critical: 
Native stacktrace:
2019-05-31 11:07:01.529403+0200 CustomRendererTest.iOS[77822:2556149] critical:     0   CustomRendererTest.iOS              0x000000010fe3a304 mono_handle_native_crash + 244
2019-05-31 11:07:01.529603+0200 CustomRendererTest.iOS[77822:2556149] critical:     1   libsystem_platform.dylib            0x000000011d8e3b5d _sigtramp + 29
2019-05-31 11:07:01.529741+0200 CustomRendererTest.iOS[77822:2556149] critical:     2   ???                                 0x0000000110517d40 0x0 + 4568743232
2019-05-31 11:07:01.529858+0200 CustomRendererTest.iOS[77822:2556149] critical:     3   libsystem_c.dylib                   0x000000011d66601d abort + 127
2019-05-31 11:07:01.529989+0200 CustomRendererTest.iOS[77822:2556149] critical:     4   CustomRendererTest.iOS              0x0000000110046aef xamarin_unhandled_exception_handler + 47
2019-05-31 11:07:01.530114+0200 CustomRendererTest.iOS[77822:2556149] critical:     5   CustomRendererTest.iOS              0x000000010fed8df7 mono_invoke_unhandled_exception_hook + 151
2019-05-31 11:07:01.530229+0200 CustomRendererTest.iOS[77822:2556149] critical:     6   CustomRendererTest.iOS              0x000000010fe39ce6 mono_handle_exception_internal + 6118
2019-05-31 11:07:0
1.530354+0200 CustomRendererTest.iOS[77822:2556149] critical:   7   CustomRendererTest.iOS              0x000000010fe384f9 mono_handle_exception + 25
2019-05-31 11:07:01.530466+0200 CustomRendererTest.iOS[77822:2556149] critical:     8   CustomRendererTest.iOS              0x000000010fdb9353 mono_amd64_throw_exception + 131
2019-05-31 11:07:01.530599+0200 CustomRendererTest.iOS[77822:2556149] critical:     9   ???                                 0x000000013e4895a7 0x0 + 5339911591
2019-05-31 11:07:01.530726+0200 CustomRendererTest.iOS[77822:2556149] critical:     10  CustomRendererTest.iOS              0x000000010fcf005c _ZL31native_to_managed_trampoline_20P11objc_objectP13objc_selectorPP11_MonoMethodj + 284
2019-05-31 11:07:01.530853+0200 CustomRendererTest.iOS[77822:2556149] critical:     11  CustomRendererTest.iOS              0x000000010fcf4674 -[__MonoMac_NSAsyncSynchronizationContextDispatcher xamarinApplySelector] + 52
2019-05-31 11:07:01.530996+0200 CustomRendererTest.iOS[77822:2556149] critical:     12  Foundation  
                        0x0000000111475878 __NSThreadPerformPerform + 331
2019-05-31 11:07:01.531260+0200 CustomRendererTest.iOS[77822:2556149] critical:     13  CoreFoundation                      0x000000011072ebe1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
2019-05-31 11:07:01.531472+0200 CustomRendererTest.iOS[77822:2556149] critical:     14  CoreFoundation                      0x000000011072e463 __CFRunLoopDoSources0 + 243
2019-05-31 11:07:01.531678+0200 CustomRendererTest.iOS[77822:2556149] critical:     15  CoreFoundation                      0x0000000110728b1f __CFRunLoopRun + 1231
2019-05-31 11:07:01.531937+0200 CustomRendererTest.iOS[77822:2556149] critical:     16  CoreFoundation                      0x0000000110728302 CFRunLoopRunSpecific + 626
2019-05-31 11:07:01.532186+0200 CustomRendererTest.iOS[77822:2556149] critical:     17  GraphicsServices                    0x0000000120a592fe GSEventRunModal + 65
2019-05-31 11:07:01.532413+0200 CustomRendererTest.iOS[77822:2556149] critical:     18  UIK
itCore                           0x0000000125ee4ba2 UIApplicationMain + 140
2019-05-31 11:07:01.532616+0200 CustomRendererTest.iOS[77822:2556149] critical:     19  ???                                 0x0000000142604bbe 0x0 + 5408574398
2019-05-31 11:07:01.532844+0200 CustomRendererTest.iOS[77822:2556149] critical:     20  ???                                 0x0000000142604953 0x0 + 5408573779
2019-05-31 11:07:01.533061+0200 CustomRendererTest.iOS[77822:2556149] critical: 
=================================================================
Got a SIGABRT while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.
=================================================================

Reproduction Link


https://github.com/PawKanarek/CustomRendererTest

Guys, this is critical, all custom renderers that my company created are using pattern that you suggested. And for now we cannot migrate to X.F 4.0. Please fix this ASAP.

        protected override void OnElementChanged(ElementChangedEventArgs<CustomView> e)
        {
            base.OnElementChanged(e);

            if (this.Control == null && this.Element != null) /// Temporary fix: add "this.Element != null"
            {
                // Instantiate the native control and assign it to the Control property with
                // the SetNativeControl method
            }
            if (e.OldElement != null)
            {
                // Unsubscribe from event handlers and cleanup any resources
            }
            if (e.NewElement != null)
            {
                // Configure the control and subscribe to event handlers
            }
         }
customrenderer 1 high regression iOS 馃崕 bug

All 11 comments

Is there already a fix for this?

Yeah, but i think its still not merged.
@rmarinho can you tell why you marked this pattern as wrong? We've been using it whole time in our company, and everything was fine until now.

The documentation already stated correctly that OnElementChanged could be called multiple times. This is because of renderer reuse (OldElement and NewElement), as well as when Disposing we are passing null as the Element so we can detach effects and other stuff. So if you think in this case , it just doesn't make sense to create a new Control when you are Disposing that control , a user can know that if a NewElement is null.
The pattern should be just create a new control if you are being passed a new element and you don't have a control yet.

Thanks for clarifying that!

This is because after upgrade to 4.0, when the iOS platform dispose, the OnElementChanged method called again, and the render called SetNativeControl method again, this throws an exception because the page has been destoried... I don't know is it corret to call SetNativeControl method in the OnElementChanged method, will it work when call it in the ctor method? On the other hand, this is not happened in Android platform... this is an ununiform behavior in each platform

I just test it... if I call the SetNativeControl method in the ctor method, it will also throws an ex, so is it the only solution that add the e.NewElement != null condition?

Yeah, that would be great if we could get knowledge about lifecycle of custom renderers. For now, to manage my custom renderers i used pattern mentioned here

protected override void OnElementChanged (ElementChangedEventArgs<NativeListView> e){
  base.OnElementChanged (e);
  if (Control == null) {  // Instantiate the native control and assign it to the Control property with
        // the SetNativeControl method}
  if (e.OldElement != null) {// Unsubscribe from event handlers and cleanup any resources }
  if (e.NewElement != null) {  // Configure the control and subscribe to event handlers }

But in another article
We see patern like this

    public class VideoPlayerRenderer : ViewRenderer<VideoPlayer, ARelativeLayout> {
        bool isPrepared;
        protected override void OnElementChanged(ElementChangedEventArgs<VideoPlayer> args)  {
            base.OnElementChanged(args);
            if (args.NewElement != null) {
                if (Control == null)   {
                    // Handle a VideoView event
                    videoView.Prepared += OnVideoViewPrepared;
                    // Use the RelativeLayout as the native control
                    SetNativeControl(relativeLayout);
                }
            }
        }

        protected override void Dispose(bool disposing){
            if (Control != null && videoView != null) {
                videoView.Prepared -= OnVideoViewPrepared;
            }
            base.Dispose(disposing);
        }
}

So which pattern is good? When we should remove/add listeners, or call SetNativeControl?
When we should free unmanaged resources? In Dispose method, or in OnElementChanged method? Im confused.

closed by #6415

Is this fix been published yet to new version. I have 4.0.0.497661 and it still seems to be an issue. Any ETA?

#6328

Even an error putting the SetNativeControl inside "if (e.NewElement! = Null)" does not generate an exception, but it also does not execute the command.
base.OnElementChanged(e); if (e.NewElement != null) { if (this.Control == null) { this.SetNativeControl(new TagUiLabel()); } this.Layer.CornerRadius = 10; this.Layer.BorderColor= ColorExtensions.ToCGColor(ColorExtensions.ToColor(UIColor.FromRGB(3, 169, 244))); this.Layer.BackgroundColor = ColorExtensions.ToCGColor(Color.GhostWhite); this.Layer.BorderWidth = 1; }

Is this somewhat a similar bug? It only happens in iOS, when returning to a previous page. VS 8.1.4 (build 5).

When navigating like this: StartPage -> Modal page -> another modal page and returning once I'm getting a crash, only on iOS.

Strange is that I don't have a Sharpnado Visual anywhere in those pages (it's in another view).
`` at Sharpnado.Presentation.Forms.iOS.Effects.iOSViewStyleEffect.OnDetached () [0x0001c] in <ec6c6356fc024ba987678ca56d694c54>:0 at Xamarin.Forms.Effect.SendDetached () [0x00009] in D:\a\1\s\Xamarin.Forms.Core\Effect.cs:62 at Xamarin.Forms.PlatformEffect2[TContainer,TControl].SendDetached () [0x00000] in D:\a\1\s\Xamarin.Forms.Core\PlatformEffect.cs:23
at Xamarin.Forms.Element.set_EffectControlProvider (Xamarin.Forms.IEffectControlProvider value) [0x0002e] in D:\a\1\s\Xamarin.Forms.Core\Element.cs:232
at Xamarin.Forms.Platform.iOS.EffectUtilities.RegisterEffectControlProvider (Xamarin.Forms.IEffectControlProvider self, Xamarin.Forms.IElementController oldElement, Xamarin.Forms.IElementController newElement) [0x0000e] in <40f1ab4c940d4cf9af06c68eae30048f>:0
at Xamarin.Forms.Platform.iOS.VisualElementRenderer1[TElement].SetElement (TElement element) [0x00144] in <40f1ab4c940d4cf9af06c68eae30048f>:0 at Xamarin.Forms.Platform.iOS.VisualElementRenderer1[TElement].Dispose (System.Boolean disposing) [0x0008c] in <40f1ab4c940d4cf9af06c68eae30048f>:0
at Xamarin.Forms.Platform.iOS.ViewRenderer2[TView,TNativeView].Dispose (System.Boolean disposing) [0x0005c] in <40f1ab4c940d4cf9af06c68eae30048f>:0 at Xamarin.Forms.Platform.iOS.ButtonRenderer.Dispose (System.Boolean disposing) [0x00064] in <40f1ab4c940d4cf9af06c68eae30048f>:0 at Foundation.NSObject.Dispose () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.10.0.157/src/Xamarin.iOS/Foundation/NSObject2.cs:147 at Xamarin.Forms.Platform.iOS.VisualElementPackager.Dispose (System.Boolean disposing) [0x0003f] in <40f1ab4c940d4cf9af06c68eae30048f>:0 at Xamarin.Forms.Platform.iOS.VisualElementPackager.Dispose () [0x00000] in <40f1ab4c940d4cf9af06c68eae30048f>:0 at Xamarin.Forms.Platform.iOS.VisualElementRenderer1[TElement].Dispose (System.Boolean disposing) [0x00058] in <40f1ab4c940d4cf9af06c68eae30048f>:0
at Foundation.NSObject.Dispose () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.10.0.157/src/Xamarin.iOS/Foundation/NSObject2.cs:147
at Xamarin.Forms.Platform.iOS.VisualElementPackager.Dispose (System.Boolean disposing) [0x0003f] in <40f1ab4c940d4cf9af06c68eae30048f>:0
at Xamarin.Forms.Platform.iOS.VisualElementPackager.Dispose () [0x00000] in <40f1ab4c940d4cf9af06c68eae30048f>:0
at Xamarin.Forms.Platform.iOS.VisualElementRenderer1[TElement].Dispose (System.Boolean disposing) [0x00058] in <40f1ab4c940d4cf9af06c68eae30048f>:0 at Foundation.NSObject.Dispose () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.10.0.157/src/Xamarin.iOS/Foundation/NSObject2.cs:147 at Xamarin.Forms.Platform.iOS.VisualElementPackager.Dispose (System.Boolean disposing) [0x0003f] in <40f1ab4c940d4cf9af06c68eae30048f>:0 at Xamarin.Forms.Platform.iOS.VisualElementPackager.Dispose () [0x00000] in <40f1ab4c940d4cf9af06c68eae30048f>:0 at Xamarin.Forms.Platform.iOS.VisualElementRenderer1[TElement].Dispose (System.Boolean disposing) [0x00058] in <40f1ab4c940d4cf9af06c68eae30048f>:0
at Foundation.NSObject.Dispose () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.10.0.157/src/Xamarin.iOS/Foundation/NSObject2.cs:147
at Xamarin.Forms.Platform.iOS.VisualElementPackager.Dispose (System.Boolean disposing) [0x0003f] in <40f1ab4c940d4cf9af06c68eae30048f>:0
at Xamarin.Forms.Platform.iOS.VisualElementPackager.Dispose () [0x00000] in <40f1ab4c940d4cf9af06c68eae30048f>:0
at Xamarin.Forms.Platform.iOS.VisualElementRenderer`1[TElement].Dispose (System.Boolean disposing) [0x00058] in <40f1ab4c940d4cf9af06c68eae30048f>:0
at Foundation.NSObject.Dispose () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.10.0.157/src/Xamarin.iOS/Foundation/NSObject2.cs:147
at Xamarin.Forms.Platform.iOS.VisualElementPackager.Dispose (System.Boolean disposing) [0x0003f] in <40f1ab4c940d4cf9af06c68eae30048f>:0
at Xamarin.Forms.Platform.iOS.VisualElementPackager.Dispose () [0x00000] in <40f1ab4c940d4cf9af06c68eae30048f>:0
at Xamarin.Forms.Platform.iOS.PageRenderer.Dispose (System.Boolean disposing) [0x00070] in <40f1ab4c940d4cf9af06c68eae30048f>:0
at Foundation.NSObject.Dispose () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.10.0.157/src/Xamarin.iOS/Foundation/NSObject2.cs:147
at Xamarin.Forms.Platform.iOS.DisposeHelpers.DisposeModalAndChildRenderers (Xamarin.Forms.Element view) [0x00041] in <40f1ab4c940d4cf9af06c68eae30048f>:0
at Xamarin.Forms.Platform.iOS.Platform.Xamarin.Forms.INavigation.PopModalAsync (System.Boolean animated) [0x00143] in <40f1ab4c940d4cf9af06c68eae30048f>:0
at Xamarin.Forms.Application+NavigationImpl.OnPopModal (System.Boolean animated) [0x0005d] in D:\a\1\s\Xamarin.Forms.Core\Application.cs:386
at MyProject.Helpers.NavigationHelper.GoBackAsync (System.Boolean animated) [0x00030]
at MyProject.ViewModel.SignInViewModel.Cancel_Executed () [0x00020]
at MyProject.ViewModel.SignInViewModel.<.ctor>b__32_3 () [0x0001f]
at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.b__6_0 (System.Object state) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.10.0.157/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1023
at Foundation.NSAsyncSynchronizationContextDispatcher.Apply () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.10.0.157/src/Xamarin.iOS/Foundation/NSAction.cs:178
--- End of stack trace from previous location where exception was thrown ---

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/12.10.0.157/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/12.10.0.157/src/Xamarin.iOS/UIKit/UIApplication.cs:65
at MyProject.iOS.Application.Main (System.String[] args) [0x00001]
```

Was this page helpful?
0 / 5 - 0 ratings