Xamarin.Forms bug? System.ObjectDisposedException: Cannot access a disposed object
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.
Xamarin.Forms bug? System.ObjectDisposedException: Cannot access a disposed object的更多相关文章
- System.Net.Sockets.Socket SendAsync System.ObjectDisposedException: Cannot access a disposed object.
发生未处理的域异常! System.ObjectDisposedException: Cannot access a disposed object. Object name: 'System.Net ...
- 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 ...
- # - 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 ...
- Cannot access a disposed object in ASP.NET Core
Cannot access a disposed object in ASP.NET Core 楠木大叔 导航 常见原因 总结 对于.neter来说,在使用ASP.NET Core的过程中 ...
- 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 ...
- Xamarin.Forms实现touch事件
Xamarin.Forms的View没有touch事件,只能自己实现 首先,在共享项目里面,放入这几个类,结构大概是这样的: using System; using Xamarin.Forms; na ...
- Xamarin.Forms 自定义 TapGestureRecognizer 附加属性
While creating Xamarin.Forms applications, definitely you are going to need TapGestureRecognizer oft ...
- 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 ...
- 老司机学新平台 - Xamarin Forms开发框架二探 (Prism vs MvvmCross)
在上一篇Xamarin开发环境及开发框架初探中,曾简单提到MvvmCross这个Xamarin下的开发框架.最近又评估了一些别的,发现老牌Mvvm框架Prism现在也支持Xamarin Forms了, ...
随机推荐
- 加密算法—MD5、RSA、DES
最近因为要做一个加密的功能,简单了解了一下加密算法,现在比较常用的有三个加密算法MD5加密算法.RSA加密算法.DES加密算法. MD5加密算法 定义:MD5算法是将任意长度的“字 ...
- 20145318赵一Java课程总结
20145318赵一Java课程总结 每周读书笔记链接汇总 问卷调查 第1周读书笔记 第2周读书笔记 第3周读书笔记 第4周读书笔记 第5周读书笔记 第6周读书笔记 第7周读书笔记 第8周读书笔记 第 ...
- linux开启oracle服务
linux下启动oracle su - oracle sqlplus /nolog conn /as sysdba startup exit lsnrctl start exit 2. linux下关 ...
- EditText的hint不显示
EditText的hint不显示可能的原因: 1.字体颜色与EditText的背景色一样; 2.使用了android:inputType = phone; 3.如果加上android:ellipsiz ...
- Jade之Filters
Filters jade允许将其他语言嵌套到jade语言之中. 支持的有:coffee-script,:babel,:uglify-js, :less,:markdown-it. jade: :mar ...
- React Native填坑之旅--动画
动画是提高用户体验不可缺少的一个元素.恰如其分的动画可以让用户更明确的感知当前的操作是什么. 无疑在使用React Native开发应用的时候也需要动画.这就需要知道RN都给我们提供了那些动画,和每个 ...
- 关闭 selinux 和防火墙
1.关闭 selinux 修改 它的配置文档 /etc/selinux/conf 修改 SELINUX=disabled 或者permissive 2. 关闭 防火墙 输入命令 systemctl d ...
- C++中复制构造函数
复制构造函数 复制构造函数用于: 根据另一个同类型的对象显示或隐式初始化一个对象 复制一个对象,将它作为实参传给一个函数 从函数返回时复制一个对象 初始化顺序容器中的元素 根据元素初始化式列表初始化数 ...
- 安装SQL Server 2008 R2 Enterprise错误:'' is not a valid login or you do not have permission
今天安装SQL Server时遇到一个恶心的Bug. ------------------------------------------------------------------------- ...
- elixir 高可用系列(三) GenEvent
概述 GenEvent 是事件处理的通用部分的抽象. 通过 GenEvent ,我们给已有的服务 动态 的添加 事件处理. GenEevent 和 GenServer 的区别 之前已经介绍了 GenS ...