Hi,

My Android Xamarin.Forms application uses a Navigation stack to display various views, I often have a list on a screen (A) that once a cell is clicked I push onto the stack a new screen (B), the user completes some form fields and then clicks a button to save. Once they click the 'save' button a task is created on the thread pool to asynchronously perform some work (no async/await and no dependency on any UI) and the view is popped back to screen (A).

Once the task is completed, it fires a simple event using the PubSub library, on the UI thread, so screen (A) has the opportunity to refresh from the local database and it does.

The problem is that when I go to drag the updated list on screen (A), the app crashes with an ObjectDisposedExceptionintermittently (like 1 in 50 times)...

System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'Android.Views.GestureDetector'.
at Java.Interop.JniPeerMembers.AssertSelf (Java.Interop.IJavaPeerable self) [0x00030] in /Users/builder/data/lanes/3819/c1d1c79c/source/Java.Interop/src/Java.Interop/Java.Interop/JniPeerMembers.cs:153
at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualBooleanMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x00002] in /Users/builder/data/lanes/3819/c1d1c79c/source/Java.Interop/src/Java.Interop/Java.Interop/JniPeerMembers.JniInstanceMethods_Invoke.cs:57
at Android.Views.GestureDetector.OnTouchEvent (Android.Views.MotionEvent ev) [0x0002c] in /Users/builder/data/lanes/3819/c1d1c79c/source/monodroid/src/Mono.Android/platforms/android-23/src/generated/Android.Views.GestureDetector.cs:1546
at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].Android.Views.View.IOnTouchListener.OnTouch (Android.Views.View v, Android.Views.MotionEvent e) [0x0003f] in C:\BuildAgent2\work\aad494dc9bc9783\Xamarin.Forms.Platform.Android\VisualElementRenderer.cs:101
at Android.Views.View+IOnTouchListenerInvoker.n_OnTouch_Landroid_view_View_Landroid_view_MotionEvent_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_v, System.IntPtr native_e) [0x00019] in /Users/builder/data/lanes/3819/c1d1c79c/source/monodroid/src/Mono.Android/platforms/android-23/src/generated/Android.Views.View.cs:3558
at at (wrapper dynamic-method) System.Object:4eaabbb9-8c1c-4ea1-b505-44c325bbb1ab (intptr,intptr,intptr,intptr)

I'm not sure why it says that I cannot access a disposed object, I'm interacting with a list with a gesture detector, it's on-screen, so it's not disposed.

Is this a bug in Xamarin.Forms?

On a similar note, if I modify an MVVP property that notifies listeners that a property has changed (I always check it's on the UI thread first), then if that's bound to a Xamarin.Forms list but it's not currently on-screen, presumably Xamarin.Forms will not barf ? After-All it's just off-screen and should still bind okay?

I've just tweaked one of my projects to explicitly set the CachingStrategy on the ListView to RecycleElement and it's not been seen since. However I believe it can have knock-on effects with Converters, but so far in my case it seems to be okay. It's too early to say conclusively whether it's fixed the issue (GestureRecognizer related ObjectDisposed), but I thought I'd offer the update just in case it helps anyone else out.

Note the auto-complete in the XAML doesn't show up, so you'll have to add

<ListView x:Name="NoStartList" ItemsSource="{Binding PollingRecordInfos}" >
<ListViewCachingStrategy>RecycleElement</ListViewCachingStrategy>

</ListView>

This is actually the opposite of what @AdamP suggested...

If you have your ListViewCachingStrategy set to RecycleElement, try disabling that and see if that stops the issue.

I never explicitly set a CachingStrategy, the default is RetainElement and given that sometimes the stack trace shows RetainElement, then I thought swapping to RecycleElement might actually help.

Fingers crossed.

from:https://forums.xamarin.com/discussion/79315/xamarin-forms-bug-system-objectdisposedexception-cannot-access-a-disposed-object

Xamarin.Forms bug? System.ObjectDisposedException: Cannot access a disposed object的更多相关文章

  1. System.Net.Sockets.Socket SendAsync System.ObjectDisposedException: Cannot access a disposed object.

    发生未处理的域异常! System.ObjectDisposedException: Cannot access a disposed object. Object name: 'System.Net ...

  2. abp Cannot access a disposed object. A common cause of this error is disposing

    框架:abp 异常信息: An unhandled exception was thrown by the application.System.ObjectDisposedException: Ca ...

  3. # - net - cannot access a disposed object r nobject name filebufferingreadstream

    .Net Core 2.1-Cannot access a disposed object.Object name: 'IServiceProvider' (3) I just migrated .N ...

  4. Cannot access a disposed object in ASP.NET Core

    Cannot access a disposed object in ASP.NET Core 楠木大叔     导航 常见原因 总结   对于.neter来说,在使用ASP.NET Core的过程中 ...

  5. asp.net Core HttpClient 出现Cannot access a disposed object. Object name: 'SocketsHttpHandler' 的问题。

    ASP.NET Core 部署在Centos 中 偶尔出现 One or more errors occurred. (Cannot access a disposed object.Object n ...

  6. Xamarin.Forms实现touch事件

    Xamarin.Forms的View没有touch事件,只能自己实现 首先,在共享项目里面,放入这几个类,结构大概是这样的: using System; using Xamarin.Forms; na ...

  7. Xamarin.Forms 自定义 TapGestureRecognizer 附加属性

    While creating Xamarin.Forms applications, definitely you are going to need TapGestureRecognizer oft ...

  8. Xamarin.Forms.Xaml.XamlParseException: MarkupExtension not found for trans:Translate using a PCL in Release Mode

    I'm pretty desperate finding the solution for the problem stated below. I have a cross platform solu ...

  9. 老司机学新平台 - Xamarin Forms开发框架二探 (Prism vs MvvmCross)

    在上一篇Xamarin开发环境及开发框架初探中,曾简单提到MvvmCross这个Xamarin下的开发框架.最近又评估了一些别的,发现老牌Mvvm框架Prism现在也支持Xamarin Forms了, ...

随机推荐

  1. RNN and LSTM saliency Predection Scene Label

    http://handong1587.github.io/deep_learning/2015/10/09/rnn-and-lstm.html  //RNN and LSTM http://hando ...

  2. 【Java】XML解析之JDOM

    JDOM介绍 JDOM是一个开源项目,它基于树型结构,利用纯JAVA的技术对XML文档实现解析.生成.序列化以及多种操作.使用jdom需要引入jdom.jar包. XML生成及解析 代码如下: pac ...

  3. json+servlet+ajax

    json-lib-2.3-jdk15.jar commons-beanutils-1.7.0.jar commons-httpclient-3.1.jar commons-lang-2.3.jar c ...

  4. webpack与gulp的区别及实例搭建

    webpack是什么,提到这个概念,很多人可能立马说出来,模块化加载器兼打包工具,可以把各种资源都作为模块来使用和处理等等. 说到前端构建工具,不可避免的会提到gulp,到底webpack和gulp有 ...

  5. git --如何撤销已放入缓存区(Index区)的修改

    修改或新增的文件通过 git add --all 命令全部加入缓存区(index区)之后,使用 git status 查看状态(git status -s 简单模式查看状态,第一列本地库和缓存区的差异 ...

  6. utime函数

    utime函数:对一个文件的访问和修改时间 #include <utime.h> int utime( const char *pathname, const struct utimbuf ...

  7. WebSphere试用过期问题处理

    WebSphere Application Server的试用期为60天,过期将无法启动WAS. E:\IBM\WebSphere\AppServer\profiles\Dmgr01\bin>s ...

  8. nginx+php 安装手册

    http://www.cnblogs.com/hxl2009/archive/2013/06/11/3131627.html  [mysql安装] php 安装 1: wget http://ftp. ...

  9. SQL Server 优化器特性导致的内存授予相关BUG

    我们有时会遇到一些坑,要不填平,要不绕过.这里为大家介绍一个相关SQL Server优化器方面的特性导致内存授予的相关BUG,及相关解决方式,也顺便回答下邹建同学的相关疑问. 问题描述 一个简单的查询 ...

  10. Redis使用总结之与Memcached异同

    Redis是什么?两句话可以做下概括: 1. 是一个完全开源免费的key-value内存数据库 2. 通常被认为是一个数据结构服务器,主要是因为其有着丰富的数据结构 strings.map. list ...