jamesmontemagno / Xamarin.Forms-PullToRefreshLayout

Pull To Refresh a ScrollView or ListView in Xamarin.Forms
218 stars 49 forks source link

Cannot access a disposed object after upgrading to Xamarin.Forms 2.3.1.114 #12

Closed MaskPZ closed 4 years ago

MaskPZ commented 8 years ago

Hi James,

First of all thank you for your great work! I'm using this control since time and it always worked perfectly!

A few days ago, I've updated to Xamarin.Forms 2.3.1.114 and since then...when I open the page containing the control the first time everything is ok but if I try to re-open it I get this:

"Unhandled Exception: System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'Refractored.XamForms.PullToRefresh.Droid.PullToRefreshLayoutRenderer'."

Same error also after app resume.

As you can see it's on Android, never tried on iOS.

Hope you will fix it.

Thank you

otorcatf commented 6 years ago

Thanks @vdmitrovich for the fix, your solution works for me. In my case I have 3 pages with PullToRefreshLayout inside of a TabbedPage and the exception throws when I move between the pages.

MysterDru commented 5 years ago

I was having a similar issues so I pulled the full renderer code into my project. I noticed there is a lot of code commented out in the Dispose method in the android renderer.

https://github.com/jamesmontemagno/Xamarin.Forms-PullToRefreshLayout/blob/4217e7dbe354163c6e9ab9d3ba54913e1d38e477/PullToRefresh/PullToRefresh.Droid/PullToRefreshLayoutRenderer.cs#L359

If i uncomment that code, the exception seems to go away.

Polyariz commented 5 years ago

Thanks @keannan5390. Uncommented the code below resolve for me the issue with "System.ObjectDisposedException: Cannot access a disposed object. Object name: 'Refractored.XamForms.PullToRefresh.Droid.PullToRefreshLayoutRenderer'".

/*if (disposing)
            {
                if (Element != null)
                {
                    Element.PropertyChanged -= HandlePropertyChanged;
                }
                if (packed != null)
                    RemoveView(packed.ViewGroup);
            }
            packed?.Dispose();
            packed = null;
            Tracker?.Dispose();
            Tracker = null;

            if (rendererProperty != null)
            {
                rendererProperty = null;
            }
            init = false;*/
nielscup commented 5 years ago

Same issue with XF 3.6.0.293080 and PullToRefresh 2.4.1 and 2.4.1.1-beta

Bogenbai commented 5 years ago

I faced the same issue. But @vdmitrovich advice helped. Thank you!

jamesmontemagno commented 5 years ago

Can someone send a pr down :)

dbwelch commented 5 years ago

Looks like jon-mccall has a fix, can this be integrated into a PullToRefresh Nuget? I use this all over my app, and, it was approved in Apple App Store, but, now I found this that causes the app to crash everywhere on Android, can someone add this fix and build? Pretty please?

SharpMobileCode commented 5 years ago

Looks like jon-mccall has a fix, can this be integrated into a PullToRefresh Nuget? I use this all over my app, and, it was approved in Apple App Store, but, now I found this that causes the app to crash everywhere on Android, can someone add this fix and build? Pretty please?

I agree and this is what should happen. But we couldn't wait and ended up copying the platform renderer files and the content view into our own project and fixing it ourselves. Fortunately it was pretty simple and straight forward with just a minor namespace change in our XAML files. But I agree, the PR has been opened for almost a month and it's disappointing.

dbwelch commented 5 years ago

Thanks, I’m doing same. But, I’m a newbie when it comes to adding manually, what is the namespace change you have to make? I imported the project into my main solution, left the namespace as before (Refactored.XamForms.PullToRefresh) under Default Namespace under the Project Options. I get a ClassNotFound exception on the PullToRefreshRenderer.

I’ve added the project under all projects and the Android target. Is the directory relevant?

Sent from my iPhone

On May 16, 2019, at 6:00 PM, Ruben Macias notifications@github.com<mailto:notifications@github.com> wrote:

Looks like jon-mccall has a fix, can this be integrated into a PullToRefresh Nuget? I use this all over my app, and, it was approved in Apple App Store, but, now I found this that causes the app to crash everywhere on Android, can someone add this fix and build? Pretty please?

I agree and this is what should happen. But we couldn't wait and ended up copying the platform renderer files and the content view into our own project and fixing it ourselves. Fortunately it was pretty simple and straight forward with just a minor namespace change in our XAML files. But I agree, the PR has been opened for almost a month and it's disappointing.

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fjamesmontemagno%2FXamarin.Forms-PullToRefreshLayout%2Fissues%2F12%3Femail_source%3Dnotifications%26email_token%3DAABUHEZOCKMPZPPI5NKLKZLPVXKRTA5CNFSM4CLWKGZKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODVTFTQY%23issuecomment-493246915&data=02%7C01%7C%7C124bccd516664db0779f08d6da49f9e4%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636936408587592464&sdata=zQDESXuB9RoJNopqtE9HiTNqmYAofq%2F%2BnlCQe%2BwuaZc%3D&reserved=0, or mute the threadhttps://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAABUHE4MUE6M2GTLSQCIGKLPVXKRTANCNFSM4CLWKGZA&data=02%7C01%7C%7C124bccd516664db0779f08d6da49f9e4%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636936408587612492&sdata=AMM6ODgtIYKonY5rpm3RTa%2BTb5rxhBRq5s9GANmAlLI%3D&reserved=0.

SharpMobileCode commented 5 years ago

Thanks, I’m doing same. But, I’m a newbie when it comes to adding manually, what is the namespace change you have to make? I imported the project into my main solution, left the namespace as before (Refactored.XamForms.PullToRefresh) under Default Namespace under the Project Options. I get a ClassNotFound exception on the PullToRefreshRenderer. I’ve added the project under all projects and the Android target. Is the directory relevant?

Sorry for the confusion. I kept the namespaces the same on the actual renderers and content view files. Then on my XAML files that use PullToRefreshLayout, I adjusted the the PullToRefresh control namespace definition to my own assembly instead of the Refractored.XamForms.PullToRefresh assembly

Old

<ContentPage 
    xmlns="http://xamarin.com/schemas/2014/forms" 
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
    x:Class="RefreshSample.Views.ScrollViewXamlPage"
    xmlns:controls="clr-namespace:Refractored.XamForms.PullToRefresh;assembly=Refractored.XamForms.PullToRefresh"
    Title="Xaml Scroll">

New

<ContentPage 
    xmlns="http://xamarin.com/schemas/2014/forms" 
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
    x:Class="RefreshSample.Views.ScrollViewXamlPage"
    xmlns:controls="clr-namespace:Refractored.XamForms.PullToRefresh;assembly=MyAppAssemblyName"
    Title="Xaml Scroll">

Notice that the value of xmlns:controls is different. Instead of it being defined in the Refractored.XamForms.PullToRefresh.dll, it's defined in my own app assembly.

dbwelch commented 5 years ago

Ruben: Thanks for the assistance and clarification. But, where is "MyAssemblyName" defined? My configuration seems very similar, but, just not sure where to pull the assembly parameter on the namespace for "controls".

Thanks! David


From: Ruben Macias notifications@github.com Sent: Friday, May 17, 2019 11:52 AM To: jamesmontemagno/Xamarin.Forms-PullToRefreshLayout Cc: dbwelch; Comment Subject: Re: [jamesmontemagno/Xamarin.Forms-PullToRefreshLayout] Cannot access a disposed object after upgrading to Xamarin.Forms 2.3.1.114 (#12)

Thanks, I’m doing same. But, I’m a newbie when it comes to adding manually, what is the namespace change you have to make? I imported the project into my main solution, left the namespace as before (Refactored.XamForms.PullToRefresh) under Default Namespace under the Project Options. I get a ClassNotFound exception on the PullToRefreshRenderer. I’ve added the project under all projects and the Android target. Is the directory relevant?

Sorry for the confusion. I kept the namespaces the same on the actual renderers and content view files. Then on my XAML files that use PullToRefreshLayout, I adjusted the the PullToRefresh control namespace definition to my own assembly instead of the Refractored.XamForms.PullToRefresh assembly

Old

<ContentPage

xmlns="http://xamarin.com/schemas/2014/forms"

xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"

x:Class="RefreshSample.Views.ScrollViewXamlPage"

xmlns:controls="clr-namespace:Refractored.XamForms.PullToRefresh;assembly=Refractored.XamForms.PullToRefresh"

Title="Xaml Scroll">

New

<ContentPage

xmlns="http://xamarin.com/schemas/2014/forms"

xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"

x:Class="RefreshSample.Views.ScrollViewXamlPage"

xmlns:controls="clr-namespace:Refractored.XamForms.PullToRefresh;assembly=MyAppAssemblyName"

Title="Xaml Scroll">

Notice that the value of xmlns:controls is different. Instead of it being defined in the Refractored.XamForms.PullToRefresh.dll, it's defined in my own app assembly.

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://eur04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fjamesmontemagno%2FXamarin.Forms-PullToRefreshLayout%2Fissues%2F12%3Femail_source%3Dnotifications%26email_token%3DAABUHE3GO3MFVLVISZHLUILPV3IE3A5CNFSM4CLWKGZKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODVVEOCQ%23issuecomment-493504266&data=02%7C01%7C%7C0f9c3aa9a50b4dde1a0208d6dadfb4d7%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636937051671087963&sdata=vqEsoNoC9FzZKbH7QJWEt5X1mOdFi4jr7oZ6J5MzFpg%3D&reserved=0, or mute the threadhttps://eur04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAABUHEZG4CAIOJRFJKX22Z3PV3IE3ANCNFSM4CLWKGZA&data=02%7C01%7C%7C0f9c3aa9a50b4dde1a0208d6dadfb4d7%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636937051671097972&sdata=ucMC%2Bzlt%2FMq6CnU0bAEVdvtO7NiJYAqIxLQTG%2Bl9RCA%3D&reserved=0.

dbwelch commented 5 years ago

I've attempted to build this myself in my project, but, apparently I'm not able to get this configured correctly in my project. The fix seems to be to comment out two lines of code, and do a build. Am I looking at this correctly? Can someone help do a Nuget build that can be pulled into the project?

dbwelch commented 5 years ago

Managed to pull in the PullToRefresh code into my project and get the Android build to run finally (yea!), but, for some reason can't call PullToRefreshLayoutRenderer.Init() in MainActivity.cs, as it doesn't find the class when I add "using Refractored.XamForms.PullToRefresh.Droid", really weird. None of the PullToRefreshLayout's work, but, at least the app doesn't crash. The error is "the type or namespace name 'XamForms' does not exist in the namespace 'Refractored'". I'm using Refractored.MvvmHelpers from Nuget also, does it "take over" everything under 'Refractored', which is preventing the import? Sorry for posting obviously newbie questions here, but, thought someone might be able to help, guess I have to change the namespace in the code also...?

jochembroekhoff commented 5 years ago

I can confirm that this PR appears to fix the issues we're experiencing. But it reaises the question as towards why that piece of code originally had been commented out.

Mustafa-ah commented 5 years ago

can any one explain this!!! when i use this structure in my page i get that exception "System.ObjectDisposedException: Cannot access a disposed object. Object name: 'Tasky.Droid.Renderers.PullToRefreshLayoutRenderer'."

` <AbsoluteLayout Padding="0" Margin="0" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" BackgroundColor="#FAFAFA">

    <ScrollView AbsoluteLayout.LayoutFlags="All" Margin="{OnPlatform Android='0,0,0,0', iOS='0,0,0,74'}"
                 AbsoluteLayout.LayoutBounds="0, 0, 1, 1">
        <customcontrol1:PullToRefreshLayout IsPullToRefreshEnabled="True"
                                           VerticalOptions="FillAndExpand"
          HorizontalOptions="FillAndExpand"
                         RefreshCommand="{Binding ViewModel.RefreshCommand}"
                        IsRefreshing="{Binding ViewModel.IsRefreshing}">
            <Grid  VerticalOptions="FillAndExpand"
          HorizontalOptions="FillAndExpand"
          RowSpacing="0" Padding="5"> ...`

but when i changed it like this it works fine ?!!

`<AbsoluteLayout Padding="0" Margin="0" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" BackgroundColor="#FAFAFA">

        <customcontrol1:PullToRefreshLayout IsPullToRefreshEnabled="True"
                                           AbsoluteLayout.LayoutFlags="All"
                                            Margin="{OnPlatform Android='0,0,0,0', iOS='0,0,0,74'}"
                 AbsoluteLayout.LayoutBounds="0, 0, 1, 1"
                         RefreshCommand="{Binding ViewModel.RefreshCommand}"
                        IsRefreshing="{Binding ViewModel.IsRefreshing}">
        <ScrollView VerticalOptions="FillAndExpand"
          HorizontalOptions="FillAndExpand">
            <Grid  VerticalOptions="FillAndExpand"
          HorizontalOptions="FillAndExpand"
          RowSpacing="0" Padding="5">

... `

K232 commented 5 years ago

@jamesmontemagno , any idea when this PR https://github.com/jamesmontemagno/Xamarin.Forms-PullToRefreshLayout/pull/66 will be released?

RodSanford commented 5 years ago

I can verify that this bug is still around. Android issue only at this point. I am using Forms 4.2.0.848062 and have tried this with release version 2.4.1 and beta version 2.4.1.1-beta. I can reproduce it.

JniPeerMembers.AssertSelf (Java.Interop.IJavaPeerable self) JniPeerMembers+JniInstanceMethods.InvokeVirtualBooleanMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) View.get_IsInLayout () ViewExtensions.MaybeRequestLayout (Android.Views.View view) D:\a\1\s\Xamarin.Forms.Platform.Android\ViewExtensions.cs:110 VisualElementTracker.HandleRedrawNeeded (System.Object sender, Xamarin.Forms.Internals.EventArg1[T] e) D:\a\1\s\Xamarin.Forms.Platform.Android\VisualElementTracker.cs:185 (wrapper delegate-invoke) System.EventHandler1[Xamarin.Forms.Internals.EventArg1[Xamarin.Forms.VisualElement]].invoke_void_object_TEventArgs(object,Xamarin.Forms.Internals.EventArg1) VisualElement.BatchCommit () D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:572 VisualElement.set_Bounds (Xamarin.Forms.Rectangle value) D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:308 VisualElement.Layout (Xamarin.Forms.Rectangle bounds) D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:686 Layout.LayoutChildIntoBoundingRegion (Xamarin.Forms.View child, Xamarin.Forms.Rectangle region, Xamarin.Forms.SizeRequest childSizeRequest) D:\a\1\s\Xamarin.Forms.Core\Layout.cs:319 StackLayout.LayoutChildren (System.Double x, System.Double y, System.Double width, System.Double height) D:\a\1\s\Xamarin.Forms.Core\StackLayout.cs:65 Layout.UpdateChildrenLayout () D:\a\1\s\Xamarin.Forms.Core\Layout.cs:266 Layout.OnSizeAllocated (System.Double width, System.Double height) D:\a\1\s\Xamarin.Forms.Core\Layout.cs:224 VisualElement.SizeAllocated (System.Double width, System.Double height) D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:784 Layout+<>c.b45_0 () D:\a\1\s\Xamarin.Forms.Core\Layout.cs:381 Thread+RunnableImplementor.Run () IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr nativethis) (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.45(intptr,intptr)