xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.62k stars 1.87k forks source link

[Bug] XamarinForms xaml Hot Reload causing System.ObjectDisposedException: Cannot access a disposed object. #12387

Open YiannisBourkelis opened 4 years ago

YiannisBourkelis commented 4 years ago

Description

During debugging, the second time I change a property inside the ProductsListPage xaml in the attached project, an exception is raised and the application crash.

Steps to Reproduce

  1. Open attached project in Visual Studio (OSX)
  2. Debug on iOS Simulator or Actual iOS Device with iOS 14.0
  3. Open ProductsList.xaml
  4. Change a property e.g StackLayout Padding="10,10,10,12"
  5. Save the changes. Hot reload will reflect the changes
  6. Change a property again. e.g. StackLayout Padding="12,10,10,12"
  7. App will crash

Expected Behavior

Hot reload should display the changes

Actual Behavior

Crash with the following

System.ObjectDisposedException: Cannot access a disposed object. Object name: 'GroupableItemsViewController`1'. at Foundation.NSObject.get_SuperHandle () [0x0004a] in /Library/Frameworks/Xamarin.iOS.framework/Versions/14.0.0.0/src/Xamarin.iOS/Foundation/NSObject2.cs:401 at UIKit.UIViewController.get_IsViewLoaded () [0x00023] in /Library/Frameworks/Xamarin.iOS.framework/Versions/14.0.0.0/src/Xamarin.iOS/UIKit/UIViewController.g.cs:2147 at Xamarin.Forms.Platform.iOS.ObservableItemsSource.NotLoadedYet () [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.iOS\CollectionView\ObservableItemsSource.cs:287 at Xamarin.Forms.Platform.iOS.ObservableItemsSource.ReloadRequired () [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.iOS\CollectionView\ObservableItemsSource.cs:292 at Xamarin.Forms.Platform.iOS.ObservableItemsSource.Add (System.Collections.Specialized.NotifyCollectionChangedEventArgs args) [0x00023] in D:\a\1\s\Xamarin.Forms.Platform.iOS\CollectionView\ObservableItemsSource.cs:163 at Xamarin.Forms.Platform.iOS.ObservableItemsSource.CollectionChanged (System.Collections.Specialized.NotifyCollectionChangedEventArgs args) [0x00061] in D:\a\1\s\Xamarin.Forms.Platform.iOS\CollectionView\ObservableItemsSource.cs:117 at Xamarin.Forms.Platform.iOS.ObservableItemsSource.CollectionChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs args) [0x000b7] in D:\a\1\s\Xamarin.Forms.Platform.iOS\CollectionView\ObservableItemsSource.cs:108 at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.b__7_0 (System.Object state) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1021 at Foundation.NSAsyncSynchronizationContextDispatcher.Apply () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/14.0.0.0/src/Xamarin.iOS/Foundation/NSAction.cs:178 at at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr) at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Library/Frameworks/Xamarin.iOS.framework/Versions/14.0.0.0/src/Xamarin.iOS/UIKit/UIApplication.cs:86 at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0000e] in /Library/Frameworks/Xamarin.iOS.framework/Versions/14.0.0.0/src/Xamarin.iOS/UIKit/UIApplication.cs:65 at invoices.iOS.Application.Main (System.String[] args) [0x00001] in /Users/yiannis/Projects/Invoices-bug/src/invoices.iOS/Main.cs:17

Basic Information

Screenshots

Screenshot 2020-10-06 at 9 26 11 PM

Screenshot 2020-10-06 at 9 31 12 PM

Reproduction Link

hot-reload-bug.zip

Workaround

VS bug #1226462

jsuarezruiz commented 4 years ago

@YiannisBourkelis Thanks for the repro sample. Can reproduce the issue.

Captura de pantalla 2020-10-07 a las 13 21 11