当我从包含ZXing BarcodeImageView的视图和带有 IsVisible="{Binding BindMe, Converter={converter:BoolConverter}}" 的标签导航回来时,我的应用程序崩溃 System.ObjectDisposedException: Cannot access a disposed object. Object name: 'Android.Widget.ImageView'.

当我从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(用于导航按钮)

<?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:prism="clr-namespace:Prism.Mvvm;assembly=Prism.Forms"

             prism:ViewModelLocator.AutowireViewModel="True"

             x:Class="TestCrash.Views.PrismContentPage1">



    <Button Text="Navigate" Command="{Binding Navigate}" />

</ContentPage>

PrismContentPage

using Prism.Commands;

using Prism.Mvvm;

using Prism.Navigation;

using System;

using System.Collections.Generic;

using System.Linq;



namespace TestCrash.ViewModels

{

            public class PrismContentPage1ViewModel : BindableBase

            {

                private readonly INavigationService _navigationService;

                public DelegateCommand Navigate { get; set; }

        public PrismContentPage1ViewModel(INavigationService navigationService)

        {

            _navigationService = navigationService;

            Navigate = new DelegateCommand(NavigateToMain);

        }



        private void NavigateToMain()

        {

            _navigationService.NavigateAsync("MainPage");

        }

    }

}

MainPage(包含ZXing和标签)

<?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>

MainPageViewModel

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";

        }

    }

}

ValueConverter

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();

        }

    }

单声道Stacktrace

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'.