Xamarin.forms Xamarin形成(棱柱)时,ZXing条码图像视图在返回时崩溃

Xamarin.forms Xamarin形成(棱柱)时,ZXing条码图像视图在返回时崩溃,xamarin.forms,xamarin.android,prism,zxing,zxing.net,Xamarin.forms,Xamarin.android,Prism,Zxing,Zxing.net,我的应用程序崩溃System.ObjectDisposedException:无法访问已处置的对象。对象名称:“Android.Widget.ImageView”。当我从包含ZXing BarcodeImageView和标签的视图返回时,IsVisible=“{Binding BindMe,Converter={Converter:BoolConverter}}” 这个问题是在我从Xamarin.Forms 2.5转到3.2.x时提出的 软件包的版本: Xamarin.Forms - 3.2.0

我的应用程序崩溃
System.ObjectDisposedException:无法访问已处置的对象。对象名称:“Android.Widget.ImageView”。
当我从包含ZXing BarcodeImageView和标签的视图返回时,
IsVisible=“{Binding BindMe,Converter={Converter:BoolConverter}}”

这个问题是在我从Xamarin.Forms 2.5转到3.2.x时提出的

软件包的版本:

Xamarin.Forms - 3.2.0.839982
Prism.Unity.Forms - 7.10.431
ZXing.Net.Mobile.Forms - 2.4.1

Xamarin.Android.Support.Design - 27.0.2.1
Xamarin.Android.Support.v4 -27.0.2.1
Xamarin.Android.Support.v7.AppCompat - 27.0.2.1
Xamarin.Android.Support.v7.CardView - 27.0.2.1
Xamarin.Android.Support.v7.MediaRouter - 27.0.2.1
PrismContentPage(用于导航按钮)

主页面(包含ZXing和标签)

值转换器

public class BoolConverter : IValueConverter

    {

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)

        {

            return !string.IsNullOrEmpty((string)value);

        }



        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)

        {

            throw new NotImplementedException();

        }

    }
单堆栈跟踪

10-17 09:29:40.769 D/Mono    ( 7417): DllImport searching in: '__Internal' ('(null)').

10-17 09:29:40.769 D/Mono    ( 7417): Searching for 'java_interop_jnienv_new_local_ref'.

10-17 09:29:40.769 D/Mono    ( 7417): Probing 'java_interop_jnienv_new_local_ref'.

10-17 09:29:40.769 D/Mono    ( 7417): Found as 'java_interop_jnienv_new_local_ref'.

10-17 09:29:40.821 D/        ( 7417): HostConnection::get() New Host Connection established 0x9c1a97c0, tid 7443

10-17 09:29:40.822 I/OpenGLRenderer( 7417): Initialized EGL, version 1.4

10-17 09:29:40.822 W/OpenGLRenderer( 7417): Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...

10-17 09:29:40.840 D/EGL_emulation( 7417): eglCreateContext: 0x9c31fb20: maj 3 min 0 rcv 3

10-17 09:29:40.850 D/EGL_emulation( 7417): eglMakeCurrent: 0x9c31fb20: ver 3 0 (tinfo 0x9c16f230)

10-17 09:29:40.851 E/eglCodecCommon( 7417): glUtilsParamSize: unknow param 0x00008cdf

10-17 09:29:40.851 E/eglCodecCommon( 7417): glUtilsParamSize: unknow param 0x00008824

10-17 09:29:40.901 D/EGL_emulation( 7417): eglMakeCurrent: 0x9c31fb20: ver 3 0 (tinfo 0x9c16f230)

10-17 09:29:41.025 D/Mono    ( 7417): Assembly Ref addref TestCrash.Android[0xab1bdba0] -> ZXing.Net.Mobile.Forms.Android[0xab1bed40]: 2

10-17 09:29:41.025 D/Mono    ( 7417): Assembly Ref addref TestCrash.Android[0xab1bdba0] -> ZXingNetMobile[0xab1bf040]: 3

10-17 09:29:41.063 D/Mono    ( 7417): DllImport searching in: '__Internal' ('(null)').

10-17 09:29:41.063 D/Mono    ( 7417): Searching for 'java_interop_jnienv_call_nonvirtual_float_method_a'.

10-17 09:29:41.063 D/Mono    ( 7417): Probing 'java_interop_jnienv_call_nonvirtual_float_method_a'.

10-17 09:29:41.063 D/Mono    ( 7417): Found as 'java_interop_jnienv_call_nonvirtual_float_method_a'.

10-17 09:29:41.105 W/art     ( 7417): JNI RegisterNativeMethods: attempt to register 0 native methods for md5270abb39e60627f0f200893b490a1ade.ViewRenderer_2

10-17 09:29:48.434 D/Mono    ( 7417): Assembly Ref addref TestCrash[0xab1be200] -> zxing.portable[0xab1bef80]: 2

10-17 09:29:48.434 D/Mono    ( 7417): Assembly Ref addref TestCrash[0xab1be200] -> ZXing.Net.Mobile.Forms[0xab1beda0]: 3

10-17 09:29:48.435 D/Mono    ( 7417): Assembly Ref addref ZXing.Net.Mobile.Forms[0xab1beda0] -> zxing.portable[0xab1bef80]: 3

10-17 09:29:48.439 D/Mono    ( 7417): Unloading image System.Collections.dll [0x9c0d3400].

10-17 09:29:48.439 D/Mono    ( 7417): Image addref System.Collections[0x9b6d4080] -> System.Collections.dll[0xaa899e00]: 5

10-17 09:29:48.439 D/Mono    ( 7417): Config attempting to parse: 'System.Collections.dll.config'.

10-17 09:29:48.439 D/Mono    ( 7417): Config attempting to parse: '/usr/local/etc/mono/assemblies/System.Collections/System.Collections.config'.

10-17 09:29:48.439 D/Mono    ( 7417): Assembly Ref addref zxing.portable[0xab1bef80] -> System.Collections[0xab1bf160]: 3

Resolved pending breakpoint at 'BoolConverter.cs:11,1' to object TestCrash.ValueConverters.BoolConverter.Convert (object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture) [0x00001].

Error while resolving expression: One or more errors occurred.

10-17 09:29:56.613 I/Choreographer( 7417): Skipped 493 frames!  The application may be doing too much work on its main thread.

10-17 09:29:56.737 D/Mono    ( 7417): Assembly Ref addref ZXing.Net.Mobile.Forms.Android[0xab1bed40] -> System[0xad997840]: 5

10-17 09:29:56.743 W/art     ( 7417): JNI RegisterNativeMethods: attempt to register 0 native methods for md5ba571508d8a3b4abfeff2ff661a05265.ZXingBarcodeImageViewRenderer

10-17 09:29:56.750 D/Mono    ( 7417): Assembly Ref addref ZXingNetMobile[0xab1bf040] -> zxing.portable[0xab1bef80]: 4

10-17 09:29:56.750 D/Mono    ( 7417): Assembly Ref addref ZXing.Net.Mobile.Forms.Android[0xab1bed40] -> zxing.portable[0xab1bef80]: 5

10-17 09:29:56.750 D/Mono    ( 7417): Assembly Ref addref ZXing.Net.Mobile.Forms.Android[0xab1bed40] -> Xamarin.Forms.Core[0xab1beb60]: 10

10-17 09:29:56.940 D/Mono    ( 7417): Unloading image System.Runtime.Extensions.dll [0x9c0d6600].

10-17 09:29:56.940 D/Mono    ( 7417): Image addref System.Runtime.Extensions[0x9b6d39c0] -> System.Runtime.Extensions.dll[0xaa89b200]: 5

10-17 09:29:56.940 D/Mono    ( 7417): Config attempting to parse: 'System.Runtime.Extensions.dll.config'.

10-17 09:29:56.940 D/Mono    ( 7417): Config attempting to parse: '/usr/local/etc/mono/assemblies/System.Runtime.Extensions/System.Runtime.Extensions.config'.

10-17 09:29:56.940 D/Mono    ( 7417): Assembly Ref addref zxing.portable[0xab1bef80] -> System.Runtime.Extensions[0xab1bfa60]: 3

Unhandled Exception:



System.ObjectDisposedException: Cannot access a disposed object.

Object name: 'Android.Widget.ImageView'.
  • 基于
    ZXingBarcodeImageView
  • 基于
    ZXingBarcodeImageViewRenderer
    https://github.com/Redth/ZXing.Net.Mobile/blob/master/Source/ZXing.Net.Mobile.Forms.Android/ZXingBarcodeImageViewRenderer.cs

  • 覆盖REGENATE方法,
    OnElementChanged
    OnElementPropertyChanged

  • 添加空检查程序(用于
    设备内外的属性和元素。BeginInvokeOnMainThread
  • 基于
    ZXingBarcodeImageView
  • 基于
    ZXingBarcodeImageViewRenderer
    https://github.com/Redth/ZXing.Net.Mobile/blob/master/Source/ZXing.Net.Mobile.Forms.Android/ZXingBarcodeImageViewRenderer.cs

  • 覆盖REGENATE方法,
    OnElementChanged
    OnElementPropertyChanged

  • 添加空检查程序(用于
    设备内外的属性和元素。BeginInvokeOnMainThread

  • 如果您使用的是Prism,我建议不要将Xamarin.Forms包从原来的2.5更新到3.0以上的版本,除非Prism告诉/允许您这样做。当我使用最新的Prism.Forms执行新项目时,它会为我安装Xamarin.Forms 3.2。所以我认为他们可以接受?这似乎是一个只在Android上出现的已知错误-如果你使用Prism,我建议不要将Xamarin.Forms包从原来的2.5更新到3.0以上,除非Prism告诉/允许你这样做。当我使用最新的Prism.Forms做一个新项目时,它会为我安装Xamarin.Forms 3.2。所以我想他们会同意吗?这似乎是一个只发生在Android上的已知错误-
    <?xml version="1.0" encoding="utf-8" ?>
    
    <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
    
                 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    
                 xmlns:zxing="clr-namespace:ZXing.Net.Mobile.Forms;assembly=ZXing.Net.Mobile.Forms"
    
                 xmlns:zxcm="clr-namespace:ZXing.Common;assembly=zxing.portable"
    
                 xmlns:converter="clr-namespace:TestCrash.ValueConverters;assembly=TestCrash"
    
                 x:Class="TestCrash.Views.MainPage"
    
                 Title="{Binding Title}">
    
    
    
        <StackLayout BackgroundColor="White">
    
            <Label Text="Test" HorizontalTextAlignment="Center" IsVisible="{Binding BindMe, Converter={converter:BoolConverter}}" />
    
            <zxing:ZXingBarcodeImageView
    
                BarcodeValue="12345678"
    
                IsEnabled="True"
    
                HorizontalOptions="FillAndExpand"
    
                VerticalOptions="FillAndExpand"
    
                HeightRequest="200"
    
                WidthRequest="200"
    
                BarcodeFormat ="QR_CODE"
    
                IsVisible="True">
    
                <zxing:ZXingBarcodeImageView.BarcodeOptions>
    
                    <zxcm:EncodingOptions Width="180" Height="180" />
    
                </zxing:ZXingBarcodeImageView.BarcodeOptions>
    
            </zxing:ZXingBarcodeImageView>
    
        </StackLayout>
    
    </ContentPage>
    
    using Prism.Commands;
    
    using Prism.Mvvm;
    
    using Prism.Navigation;
    
    using System;
    
    using System.Collections.Generic;
    
    using System.Linq;
    
    using System.Text;
    
    
    
    namespace TestCrash.ViewModels
    
    {
    
        public class MainPageViewModel : ViewModelBase
    
        {
    
            private string _bindMe;
    
            public string BindMe
    
            {
    
                get => _bindMe;
    
                set
    
                {
    
                    SetProperty(ref _bindMe, value);
    
                }
    
    
    
            }
    
            public MainPageViewModel(INavigationService navigationService)
    
                : base(navigationService)
    
            {
    
                Title = "Main Page";
    
            }
    
        }
    
    }
    
    public class BoolConverter : IValueConverter
    
        {
    
            public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    
            {
    
                return !string.IsNullOrEmpty((string)value);
    
            }
    
    
    
            public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    
            {
    
                throw new NotImplementedException();
    
            }
    
        }
    
    10-17 09:29:40.769 D/Mono    ( 7417): DllImport searching in: '__Internal' ('(null)').
    
    10-17 09:29:40.769 D/Mono    ( 7417): Searching for 'java_interop_jnienv_new_local_ref'.
    
    10-17 09:29:40.769 D/Mono    ( 7417): Probing 'java_interop_jnienv_new_local_ref'.
    
    10-17 09:29:40.769 D/Mono    ( 7417): Found as 'java_interop_jnienv_new_local_ref'.
    
    10-17 09:29:40.821 D/        ( 7417): HostConnection::get() New Host Connection established 0x9c1a97c0, tid 7443
    
    10-17 09:29:40.822 I/OpenGLRenderer( 7417): Initialized EGL, version 1.4
    
    10-17 09:29:40.822 W/OpenGLRenderer( 7417): Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
    
    10-17 09:29:40.840 D/EGL_emulation( 7417): eglCreateContext: 0x9c31fb20: maj 3 min 0 rcv 3
    
    10-17 09:29:40.850 D/EGL_emulation( 7417): eglMakeCurrent: 0x9c31fb20: ver 3 0 (tinfo 0x9c16f230)
    
    10-17 09:29:40.851 E/eglCodecCommon( 7417): glUtilsParamSize: unknow param 0x00008cdf
    
    10-17 09:29:40.851 E/eglCodecCommon( 7417): glUtilsParamSize: unknow param 0x00008824
    
    10-17 09:29:40.901 D/EGL_emulation( 7417): eglMakeCurrent: 0x9c31fb20: ver 3 0 (tinfo 0x9c16f230)
    
    10-17 09:29:41.025 D/Mono    ( 7417): Assembly Ref addref TestCrash.Android[0xab1bdba0] -> ZXing.Net.Mobile.Forms.Android[0xab1bed40]: 2
    
    10-17 09:29:41.025 D/Mono    ( 7417): Assembly Ref addref TestCrash.Android[0xab1bdba0] -> ZXingNetMobile[0xab1bf040]: 3
    
    10-17 09:29:41.063 D/Mono    ( 7417): DllImport searching in: '__Internal' ('(null)').
    
    10-17 09:29:41.063 D/Mono    ( 7417): Searching for 'java_interop_jnienv_call_nonvirtual_float_method_a'.
    
    10-17 09:29:41.063 D/Mono    ( 7417): Probing 'java_interop_jnienv_call_nonvirtual_float_method_a'.
    
    10-17 09:29:41.063 D/Mono    ( 7417): Found as 'java_interop_jnienv_call_nonvirtual_float_method_a'.
    
    10-17 09:29:41.105 W/art     ( 7417): JNI RegisterNativeMethods: attempt to register 0 native methods for md5270abb39e60627f0f200893b490a1ade.ViewRenderer_2
    
    10-17 09:29:48.434 D/Mono    ( 7417): Assembly Ref addref TestCrash[0xab1be200] -> zxing.portable[0xab1bef80]: 2
    
    10-17 09:29:48.434 D/Mono    ( 7417): Assembly Ref addref TestCrash[0xab1be200] -> ZXing.Net.Mobile.Forms[0xab1beda0]: 3
    
    10-17 09:29:48.435 D/Mono    ( 7417): Assembly Ref addref ZXing.Net.Mobile.Forms[0xab1beda0] -> zxing.portable[0xab1bef80]: 3
    
    10-17 09:29:48.439 D/Mono    ( 7417): Unloading image System.Collections.dll [0x9c0d3400].
    
    10-17 09:29:48.439 D/Mono    ( 7417): Image addref System.Collections[0x9b6d4080] -> System.Collections.dll[0xaa899e00]: 5
    
    10-17 09:29:48.439 D/Mono    ( 7417): Config attempting to parse: 'System.Collections.dll.config'.
    
    10-17 09:29:48.439 D/Mono    ( 7417): Config attempting to parse: '/usr/local/etc/mono/assemblies/System.Collections/System.Collections.config'.
    
    10-17 09:29:48.439 D/Mono    ( 7417): Assembly Ref addref zxing.portable[0xab1bef80] -> System.Collections[0xab1bf160]: 3
    
    Resolved pending breakpoint at 'BoolConverter.cs:11,1' to object TestCrash.ValueConverters.BoolConverter.Convert (object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture) [0x00001].
    
    Error while resolving expression: One or more errors occurred.
    
    10-17 09:29:56.613 I/Choreographer( 7417): Skipped 493 frames!  The application may be doing too much work on its main thread.
    
    10-17 09:29:56.737 D/Mono    ( 7417): Assembly Ref addref ZXing.Net.Mobile.Forms.Android[0xab1bed40] -> System[0xad997840]: 5
    
    10-17 09:29:56.743 W/art     ( 7417): JNI RegisterNativeMethods: attempt to register 0 native methods for md5ba571508d8a3b4abfeff2ff661a05265.ZXingBarcodeImageViewRenderer
    
    10-17 09:29:56.750 D/Mono    ( 7417): Assembly Ref addref ZXingNetMobile[0xab1bf040] -> zxing.portable[0xab1bef80]: 4
    
    10-17 09:29:56.750 D/Mono    ( 7417): Assembly Ref addref ZXing.Net.Mobile.Forms.Android[0xab1bed40] -> zxing.portable[0xab1bef80]: 5
    
    10-17 09:29:56.750 D/Mono    ( 7417): Assembly Ref addref ZXing.Net.Mobile.Forms.Android[0xab1bed40] -> Xamarin.Forms.Core[0xab1beb60]: 10
    
    10-17 09:29:56.940 D/Mono    ( 7417): Unloading image System.Runtime.Extensions.dll [0x9c0d6600].
    
    10-17 09:29:56.940 D/Mono    ( 7417): Image addref System.Runtime.Extensions[0x9b6d39c0] -> System.Runtime.Extensions.dll[0xaa89b200]: 5
    
    10-17 09:29:56.940 D/Mono    ( 7417): Config attempting to parse: 'System.Runtime.Extensions.dll.config'.
    
    10-17 09:29:56.940 D/Mono    ( 7417): Config attempting to parse: '/usr/local/etc/mono/assemblies/System.Runtime.Extensions/System.Runtime.Extensions.config'.
    
    10-17 09:29:56.940 D/Mono    ( 7417): Assembly Ref addref zxing.portable[0xab1bef80] -> System.Runtime.Extensions[0xab1bfa60]: 3
    
    Unhandled Exception:
    
    
    
    System.ObjectDisposedException: Cannot access a disposed object.
    
    Object name: 'Android.Widget.ImageView'.