Skip to content
This repository has been archived by the owner on Nov 12, 2020. It is now read-only.

On mainpage change I got error Object reference not set to an instance of an object #97

Open
JFDionne opened this issue May 22, 2019 · 11 comments

Comments

@JFDionne
Copy link

Hi, thank for this controls.
When I change my App.mainpage to something else, the app crash and I got this error:

Object reference not set to an instance of an object

at Xfx.Controls.iOS.Renderers.XfxEntryRendererTouch.OnElementChanged (Xamarin.Forms.Platform.iOS.ElementChangedEventArgs1[TElement] e) [0x00015] in <f2149ff8a79944c98fa707a3abffd0b5>:0 at Xamarin.Forms.Platform.iOS.VisualElementRenderer1[TElement].SetElement (TElement element) [0x0012a] in <db147fad2aa9412c845ff0ead92dfe20>:0 at Xamarin.Forms.Platform.iOS.VisualElementRenderer1[TElement].Dispose (System.Boolean disposing) [0x0008c] in <db147fad2aa9412c845ff0ead92dfe20>:0 at Xamarin.Forms.Platform.iOS.ViewRenderer2[TView,TNativeView].Dispose (System.Boolean disposing) [0x0005c] in <db147fad2aa9412c845ff0ead92dfe20>:0 at Foundation.NSObject.Dispose () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.8.0.2/src/Xamarin.iOS/Foundation/NSObject2.cs:147 at Xamarin.Forms.Platform.iOS.VisualElementPackager.Dispose (System.Boolean disposing) [0x0003f] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementPackager.cs:69 at Xamarin.Forms.Platform.iOS.VisualElementPackager.Dispose () [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementPackager.cs:37 at Xamarin.Forms.Platform.iOS.VisualElementRenderer1[TElement].Dispose (System.Boolean disposing) [0x00058] in <db147fad2aa9412c845ff0ead92dfe20>:0 at Foundation.NSObject.Dispose () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.8.0.2/src/Xamarin.iOS/Foundation/NSObject2.cs:147 at Xamarin.Forms.Platform.iOS.VisualElementPackager.Dispose (System.Boolean disposing) [0x0003f] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementPackager.cs:69 at Xamarin.Forms.Platform.iOS.VisualElementPackager.Dispose () [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementPackager.cs:37 at Xamarin.Forms.Platform.iOS.VisualElementRenderer1[TElement].Dispose (System.Boolean disposing) [0x00058] in <db147fad2aa9412c845ff0ead92dfe20>:0 at Foundation.NSObject.Dispose () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.8.0.2/src/Xamarin.iOS/Foundation/NSObject2.cs:147 at Xamarin.Forms.Platform.iOS.VisualElementPackager.Dispose (System.Boolean disposing) [0x0003f] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementPackager.cs:69 at Xamarin.Forms.Platform.iOS.VisualElementPackager.Dispose () [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementPackager.cs:37 at Xamarin.Forms.Platform.iOS.VisualElementRenderer1[TElement].Dispose (System.Boolean disposing) [0x00058] in <db147fad2aa9412c845ff0ead92dfe20>:0 at Foundation.NSObject.Dispose () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.8.0.2/src/Xamarin.iOS/Foundation/NSObject2.cs:147 at Xamarin.Forms.Platform.iOS.VisualElementPackager.Dispose (System.Boolean disposing) [0x0003f] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementPackager.cs:69 at Xamarin.Forms.Platform.iOS.VisualElementPackager.Dispose () [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementPackager.cs:37 at Xamarin.Forms.Platform.iOS.VisualElementRenderer1[TElement].Dispose (System.Boolean disposing) [0x00058] in <db147fad2aa9412c845ff0ead92dfe20>:0 at Foundation.NSObject.Dispose () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.8.0.2/src/Xamarin.iOS/Foundation/NSObject2.cs:147 at Xamarin.Forms.Platform.iOS.VisualElementPackager.Dispose (System.Boolean disposing) [0x0003f] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementPackager.cs:69 at Xamarin.Forms.Platform.iOS.VisualElementPackager.Dispose () [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementPackager.cs:37 at Xamarin.Forms.Platform.iOS.VisualElementRenderer1[TElement].Dispose (System.Boolean disposing) [0x00058] in <db147fad2aa9412c845ff0ead92dfe20>:0 at Foundation.NSObject.Dispose () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.8.0.2/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.System.IDisposable.Dispose () [0x00048] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Platform.cs:83 at Xamarin.Forms.Platform.iOS.FormsApplicationDelegate.UpdateMainPage () [0x00022] in D:\a\1\s\Xamarin.Forms.Platform.iOS\FormsApplicationDelegate.cs:181 at Xamarin.Forms.Platform.iOS.FormsApplicationDelegate.ApplicationOnPropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs args) [0x00012] in D:\a\1\s\Xamarin.Forms.Platform.iOS\FormsApplicationDelegate.cs:142 at Xamarin.Forms.BindableObject.OnPropertyChanged (System.String propertyName) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:211 at Xamarin.Forms.Element.OnPropertyChanged (System.String propertyName) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Element.cs:353 at Xamarin.Forms.Application.set_MainPage (Xamarin.Forms.Page value) [0x00092] in D:\a\1\s\Xamarin.Forms.Core\Application.cs:105 at FTAC.CS.clsWebservice+<>c.<Verification_Login>b__1_2 () [0x00017] in C:\Dev\5\FTAC\FTAC\FTAC\CS\clsWebservice.cs:37 at Foundation.NSAsyncActionDispatcher.Apply () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.8.0.2/src/Xamarin.iOS/Foundation/NSAction.cs:152 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.8.0.2/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.8.0.2/src/Xamarin.iOS/UIKit/UIApplication.cs:63 at FTAC.iOS.Application.Main (System.String[] args) [0x00002] in C:\Dev\5\FTAC\FTAC\FTAC.iOS\Main.cs:19

@ChaseFlorell
Copy link
Contributor

can you please give me a working repro of this issue?

@JFDionne
Copy link
Author

JFDionne commented May 24, 2019

Yes, there we go:
https://github.com/JFDionne/Xfx.Controls.Test

But it's pretty simple, just create a new project, add your controls, put a newpage and run :)

*Update
You just need to take your project, update from Form 3.5 to 4.0 and with your example it will do the same error.

@csteeg
Copy link

csteeg commented Jun 4, 2019

@ChaseFlorell this is because in xamarin 4 Dispose is called correctly on the renderer (wonder why it didn't in previous versions though)... Control is null when getting in OnElementChanged, so the unsubscribes fail. So the onelementchanged should check if Control != null where applicable

I use this customrenderer as temporary workaround (reset element before control is reset):

public class CustomXfxEntryRendererTouch : XfxEntryRendererTouch
    {
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                SetElement(null); //trigger elementchange before base dispose happens https://github.com/XamFormsExtended/Xfx.Controls/issues/97
            }

            base.Dispose(disposing);
        }
    }

@j-h-m
Copy link

j-h-m commented Sep 11, 2019

Late comment... but I ran into the same error using Xamarin.Forms 4.X on iOS.

My solution was to downgrade Xamarin.Forms to version 3.5.0.129452 (which is the version this package is built on).

@JimmyBarrientos
Copy link

JimmyBarrientos commented Oct 10, 2019

Make sure to add the ExportRenderer. I'm brand spanking new to xamarin and C#, so I figured this would help those still learning. Feed control being used in page (XfxEntry) and your custom renderer (CustomXfxEntryRendererTouch).

[assembly: ExportRenderer(typeof(XfxEntry), typeof(CustomXfxEntryRendererTouch))]
namespace Application.iOS.CustomRenderer
{
    public class CustomXfxEntryRendererTouch : XfxEntryRendererTouch
    {
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                SetElement(null); //trigger elementchange before base dispose happens https://github.com/XamFormsExtended/Xfx.Controls/issues/97
            }

            base.Dispose(disposing);
        }
    }
}

@JackMakhoul
Copy link

I did implement the CustomXfxEntryRendererTouch but i'm still getting the same error any ideas?

@rubberydev
Copy link

Make sure to add the ExportRenderer. I'm brand spanking new to xamarin and C#, so I figured this would help those still learning. Feed control being used in page (XfxEntry) and your custom renderer (CustomXfxEntryRendererTouch).

[assembly: ExportRenderer(typeof(XfxEntry), typeof(CustomXfxEntryRendererTouch))]
namespace Application.iOS.CustomRenderer
{
    public class CustomXfxEntryRendererTouch : XfxEntryRendererTouch
    {
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                SetElement(null); //trigger elementchange before base dispose happens https://github.com/XamFormsExtended/Xfx.Controls/issues/97
            }

            base.Dispose(disposing);
        }
    }
}

This solved my problem, thanks @JimmyBarrientos

@butter5
Copy link

butter5 commented Dec 10, 2019

Using Xamarin Forms 4.3, I've tried the above but the CustomXfxEntryRendererTouch doesn't get instantiated. I've added the assembly too. Still getting the same error. Does anybody have any more ideas please?

@j-h-m
Copy link

j-h-m commented Dec 10, 2019

Using Xamarin Forms 4.3, I've tried the above but the CustomXfxEntryRendererTouch doesn't get instantiated. I've added the assembly too. Still getting the same error. Does anybody have any more ideas please?

Someone needs to update this library to run on a newer version of XF. I wound up using an entry and listview on a separate page activated by a button to get the autocomplete functionality.

@ChaseFlorell
Copy link
Contributor

I'm the owner of the code, unfortunately I haven't had the need to use this for quite some time, so I've let it fall into disrepair. I'd like to continue maintaining it, it's just a pile of time that I don't have. I do take PR's, however I'll still need to put some effort into deploying nuget updates.

@tiberiup
Copy link

@JackMakhoul, @j-h-m, I had to create a new class inheriting from XfxEntry, and asociate the renderer with it:

namespace Application.Controls
{
    public class CustomXfxEntry : XfxEntry
    {

    }
}
[assembly: ExportRenderer(typeof(CustomXfxEntry), typeof(CustomXfxEntryRendererTouch))]
namespace Application.iOS.Renderers
{
    public class CustomXfxEntryRendererTouch : XfxEntryRendererTouch
    {
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                SetElement(null); //trigger elementchange before base dispose happens https://github.com/XamFormsExtended/Xfx.Controls/issues/97
            }

            base.Dispose(disposing);
        }
    }
}

Obviously in your page you need to use this control instead of the original one, and you have to go through the same process if you're using XfxComboBox too.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants