It seems in some cases LayoutSubviews can be called before SetElement. Then _shellScrollTracker is null.
Let me know if you need more information. I can reproduce when I change oriention of device.
2019-02-07 17:07:40.518787+0100 NewsApp.iOS[98595:24576357] ConvertToNSExceptionAndAbort
2019-02-07 17:07:40.519889+0100 NewsApp.iOS[98595:24576357] Inserted Xamarin Exception Stack Line!
2019-02-07 17:07:40.520046+0100 NewsApp.iOS[98595:24576357] Name: System.NullReferenceException
2019-02-07 17:07:40.520190+0100 NewsApp.iOS[98595:24576357] Message: System.NullReferenceException: Object reference not set to an instance of an objectXamarin Exception Stack:
at Xamarin.Forms.Platform.iOS.ScrollViewRenderer.LayoutSubviews () [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Renderers\ScrollViewRenderer.cs:122
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/12.2.1.11/src/Xamarin.iOS/UIKit/UIApplication.cs:79
at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0002c] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.2.1.11/src/Xamarin.iOS/UIKit/UIApplication.cs:63
at NewsApp.iOS.Application.Main (System
.String[] args) [0x00001] in C:\FI\DialogAll\NewsApp\NewsApp\NewsApp.iOS\Main.cs:17
2019-02-07 17:07:40.560412+0100 NewsApp.iOS[98595:24576357] dynamic_cast error 2: One or more of the following type_info's has hidden visibility. They should all have public visibility. N10__cxxabiv116__shim_type_infoE, id, N10__cxxabiv117__pbase_type_infoE.
2019-02-07 17:07:40.560595+0100 NewsApp.iOS[98595:24576357] dynamic_cast error 2: One or more of the following type_info's has hidden visibility. They should all have public visibility. N10__cxxabiv116__shim_type_infoE, id, N10__cxxabiv117__pbase_type_infoE.
2019-02-07 17:07:40.560754+0100 NewsApp.iOS[98595:24576357] dynamic_cast error 2: One or more of the following type_info's has hidden visibility. They should all have public visibility. N10__cxxabiv116__shim_type_infoE, id, N10__cxxabiv117__pbase_type_infoE.
The app has been terminated
Would you please attach a sample project that demonstrates this issue? Thank you!
@samhouts thanks for the quick reply. I tried setting up a small sample but failed. But i can add some additional Information:
iPad Pro Simulator 12.1: works
iPad Pro Device: works
iPhone 6 Simulator 12.1: crash
iPhone 6 12.1.2: crash
iPhone 6 Simulator 10.3.1: works
Sorry that I can't be more helpful but I tried fixing it and it works. I don't claim to understand the root cause and I don't know if this "fix" is good. Here is what I did:
https://github.com/mclillill/Xamarin.Forms/commit/d05a54bd112cd0cd20c9158924141381debe47b8
We are also seeing this crash in our app when upgraded to 3.5.
Can someone please attach a reproduction sample? The chances of getting this fixed can grow dramatically...
It's not easy to carve out of the project code-base quickly, sorry.
It looks like it happens when an invisible scrollview that is on a page which is no-longer the main page is set to be the main page once again. (At least, that seems to be the distinction of this event in our app compared to all the ones that still work!)
Looking at the code in Xamarin.Forms/Xamarin.Forms.Platform.iOS/Renderers/ScrollViewRenderer.cs it looks fairly clear that the crash happens if LayoutSubviews() is called before SetElement(), which presumably happens if the scroll view is hidden?
If it helps anyone else, I have worked around the crash by putting the invisible scroll view in a containing stack layout and making that invisible instead.
@andreinitescu Yes, that's true a repo sample would be great. But have a look at ScrollViewRenderer.cs. What stopping anyone from calling LayoutSubviews() before SetElement()? In this case there will always be a crash. This can't be intentional, i think?
I'm also getting a nullreference exception in the scrollviewrenderer. It looks like it is trying to set the properties for the scrollbar and the scrollbar isn't ready yet.
This code worked in 3.4...
protected override void OnElementChanged(VisualElementChangedEventArgs e)
{
base.OnElementChanged(e);
global::Android.Widget.ScrollView droidScrollView = (global::Android.Widget.ScrollView)this;
droidScrollView.HorizontalScrollBarEnabled = false;
droidScrollView.VerticalFadingEdgeEnabled = true;
droidScrollView.SetFadingEdgeLength(70);
droidScrollView.VerticalScrollBarEnabled = true;
droidScrollView.ScrollbarFadingEnabled = false;
}
The conversion of a scrollviewrenderer to a scrollview no longer works in XF3.5. It appears the renderer no longer inherits a scrollview but a nestedscrollview.
So now in XF 3.5, my scrollviewrenderer looks like this...
protected override void OnElementChanged(VisualElementChangedEventArgs e)
{
base.OnElementChanged(e);
this.HorizontalScrollBarEnabled = false;
this.VerticalFadingEdgeEnabled = true;
this.SetFadingEdgeLength(70);
this.VerticalScrollBarEnabled = true;
this.ScrollbarFadingEnabled = false;
}
It doesn't like setting properties for a scrollbar that isn't instantiated yet. if i comment out all my custom property assignments, it works of course.
Caused by #4522
@samhouts Thanks!
I have something similar in 4.4.0.991210-pre2
IPhone 7, iOS v13.1.3
NullReferenceException
at Xamarin.Forms.Platform.iOS.StructuredItemsViewRenderer
have a lot of IsVisible Bindings and other bindings in my XAML
in XAML you can mainly find two CollectionViews, StackLayout, FlexButtons
It is reproducible when one of the Collectionviews visibility changes from hidden to IsVisible and back to hidden, and then in my shell navigating to an entry in another Shell's Flyoutitem and then back to entry this same entry where I have this views.
Strangely if I just swith from entries in the same Shell's FlyoutItem the exception doesn't occur.
Unfortunatelly can not provide an example code in quick notice.
Full stack trace:
at Xamarin.Forms.Platform.iOS.StructuredItemsViewRenderer2[TItemsView,TViewController].LayoutSubviews () [0x0000c] in <4f759157e6f148a992d3fa3b90518ad0>:0
at (wrapper managed-to-native) ObjCRuntime.Messaging.void_objc_msgSend(intptr,intptr)
at CoreAnimation.CALayer.LayoutSublayers () [0x00008] in /Library/Frameworks/Xamarin.iOS.framework/Versions/13.6.0.12/src/Xamarin.iOS/CALayer.g.cs:508
at Xamarin.Forms.Platform.iOS.VisualElementTracker+<>c__DisplayClass29_0.<OnUpdateNativeControl>g__update|0 () [0x00162] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementTracker.cs:252
at Xamarin.Forms.Platform.iOS.VisualElementTracker.OnUpdateNativeControl (CoreAnimation.CALayer caLayer) [0x002be] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementTracker.cs:324
at Xamarin.Forms.Platform.iOS.VisualElementTracker.UpdateNativeControl () [0x00060] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementTracker.cs:376
at Xamarin.Forms.Platform.iOS.VisualElementTracker.SetElement (Xamarin.Forms.VisualElement oldElement, Xamarin.Forms.VisualElement newElement) [0x00055] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementTracker.cs:352
at Xamarin.Forms.Platform.iOS.VisualElementTracker..ctor (Xamarin.Forms.Platform.iOS.IVisualElementRenderer renderer, System.Boolean trackFrame) [0x0006b] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementTracker.cs:50
at Xamarin.Forms.Platform.iOS.VisualElementTracker..ctor (Xamarin.Forms.Platform.iOS.IVisualElementRenderer renderer) [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementTracker.cs:36
at Xamarin.Forms.Platform.iOS.VisualElementRenderer1[TElement].SetElement (TElement element) [0x0009f] in <4f759157e6f148a992d3fa3b90518ad0>:0
at Xamarin.Forms.Platform.iOS.VisualElementRenderer1[TElement].Xamarin.Forms.Platform.iOS.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00000] in <4f759157e6f148a992d3fa3b90518ad0>:0
at Xamarin.Forms.Platform.iOS.Platform.CreateRenderer (Xamarin.Forms.VisualElement element) [0x00014] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Platform.cs:188
at Xamarin.Forms.Platform.iOS.VisualElementPackager.OnChildAdded (Xamarin.Forms.VisualElement view) [0x0003e] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementPackager.cs:99
at Xamarin.Forms.Platform.iOS.VisualElementPackager.Load () [0x0001e] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementPackager.cs:48
at Xamarin.Forms.Platform.iOS.VisualElementRenderer1[TElement].SetElement (TElement element) [0x000de] in <4f759157e6f148a992d3fa3b90518ad0>:0
at Xamarin.Forms.Platform.iOS.VisualElementRenderer`1[TElement].Xamarin.Forms.Platform.iOS.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00000] in <4f759157e6f148a992d3fa3b90518ad0>:0
at Xamarin.Forms.Platform.iOS.Platform.CreateRenderer (Xamarin.Forms.VisualElement element) [0x00014] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Platform.cs:188
at Xamarin.Forms.Platform.iOS.VisualElementPackager.OnChildAdded (Xamarin.Forms.VisualElement view) [0x0003e] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementPackager.cs:99
at Xamarin.Forms.Platform.iOS.VisualElementPackager.Load () [0x0001e] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementPackager.cs:48
at Xamarin.Forms.Platform.iOS.PageRenderer.ViewDidLoad () [0x0008f] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Renderers\PageRenderer.cs:238
at (wrapper managed-to-native) ObjCRuntime.Messaging.IntPtr_objc_msgSendSuper(intptr,intptr)
at UIKit.UIViewController.get_View () [0x0002a] in /Library/Frameworks/Xamarin.iOS.framework/Versions/13.6.0.12/src/Xamarin.iOS/UIViewController.g.cs:3171
at Xamarin.Forms.Platform.iOS.PageRenderer.get_NativeView () [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Renderers\PageRenderer.cs:104
at Xamarin.Forms.Platform.iOS.PageRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x0003d] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Renderers\PageRenderer.cs:120
at Xamarin.Forms.Platform.iOS.Platform.CreateRenderer (Xamarin.Forms.VisualElement element) [0x00014] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Platform.cs:188
at Xamarin.Forms.Platform.iOS.ShellSectionRootRenderer.LoadRenderers () [0x00028] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Renderers\ShellSectionRootRenderer.cs:146
at Xamarin.Forms.Platform.iOS.ShellSectionRootRenderer.ViewDidLoad () [0x00035] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Renderers\ShellSectionRootRenderer.cs:63
at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)