Tuesday, July 5, 2022
HomeiOS Developmentc# - Xamarin iOS app crashes when altering from Panorama orientation to...

c# – Xamarin iOS app crashes when altering from Panorama orientation to Portrait orientation

[ad_1]

TLDR
Xamarin.Varieties 5.0.0.2401 app crashes when going from Panorama orientation to view with collectionview that’s in Portrait orientation.

Context

Hello, i’ve a Xamarin.Varieties 5.0.0.2401 that has a default setting within the AppDelegate.cs that the app ought to at all times in Portrait orientation with the one exception from one view that’s acknowledged within the override methodology GetSupportedInterfaceOrientations.

Code from AppDelegate:

public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations(UIApplication software, [Transient] UIWindow forWindow)
{
   if (Shell.Present.Navigation.ModalStack.LastOrDefault() is CardPage)
   {
      return UIInterfaceOrientationMask.Panorama;
   }

   return UIInterfaceOrientationMask.Portrait;
}

However when i navigate out from the panorama view to a view with a collectionview that’s earlier full of objects on account of scrolling the app crashes.

I navigate by way of utilizing following code:

Code inside viewmodel for CardPage that’s being compelled to lanscape orientation by code in AppDelegate.cs

async Activity ExecuteCloseCommand() => await GoToAsync("..", true);

Code from BaseViewModel (that CardPage inheirts from) to deal with navigation within the stack.

protected Activity GoToAsync(string uri, bool animate = false)
            => MainThread.InvokeOnMainThreadAsync(async () => await Shell.Present.GoToAsync(uri, animate));

Error message on crash

However the exception i get from the crash is following:

{System.NullReferenceException: Object reference not set to an occasion of an object at Xamarin.Varieties.Platform.iOS.ItemsViewController1[TItemsView].CheckForEmptySource () [0x00028] in D:a_work1sXamarin.Varieties.Platform.iOSCollectionViewItemsViewController.cs:117 at Xamarin.Varieties.Platform.iOS.ItemsViewController1[TItemsView].NumberOfSections (UIKit.UICollectionView collectionView) [0x00000] in D:a_work1sXamarin.Varieties.Platform.iOSCollectionViewItemsViewController.cs:256
at (wrapper managed-to-native) ObjCRuntime.Messaging.void_objc_msgSendSuper(intptr,intptr)
at UIKit.UICollectionViewLayout.PrepareLayout () [0x00023] in /Customers/builder/azdo/_work/1/s/xamarin-macios/src/construct/ios/native/UIKit/UICollectionViewLayout.g.cs:496
at Xamarin.Varieties.Platform.iOS.ItemsViewLayout.PrepareLayout () [0x00000] in D:a_work1sXamarin.Varieties.Platform.iOSCollectionViewItemsViewLayout.cs:415
at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
at UIKit.UIApplication.Foremost (System.String[] args, System.Sort principalClass, System.Sort delegateClass) [0x0003b] in /Customers/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:85
at .iOS.Software.Foremost (System.String[] args) [0x00001] in C:UsersJesperEngdahlsourcerepos<ProjectName>Foremost.cs:17 }

So i think that there’s something in Xamarin.Varieties.Platform.iOS that’s making the crash particularly the ItemsViewController on line 117. That it’s one way or the other making a assumption that the collectionview is empty, however its not after which it craches.

I’m kinda stumped and not likely positive the best way to deal with this sort of crash, please assist.

[ad_2]

RELATED ARTICLES

Most Popular

Recent Comments