Skip to content

BottomTabItem.IsTextVisible=False leads to null reference exception on app launch if set from external ResourceDictionary #95

@jbachelor

Description

@jbachelor

Platform (please complete the following information):

  • OS: Both
  • Device: iPhone 11 simulator running 13.2; Android Pixel 3 emulator running API 29
  • Xamarin.Forms: 4.4.0.99.1265

Describe the bug
If you create an implicit style for the BottomTabItem type in the Resources section of the ContentPage that also contains the TabHostView, everything works fine. If, however, you define your style in an external file such as App.xaml, apps will crash on launch with a null reference exception if the style includes setting the IsTextVisible property to False.

To Reproduce
Issue is reproduced in this repo: https://github.com/jbachelor/XamFormsSample/tree/sharpnadoIsTextVisibleIssue

Steps to reproduce the behavior:

  1. Create a simple app using Sharpnado.
  2. Create a TabHostView with a few tabs at the bottom of the page.
  3. Define a Style for the BottomTabItem type in App.xaml, and set the IsTextVisible property to False.
  4. Run the app - crashes on launch.

Exceptions (if applicable)
Copy paste the exception and the stack trace

System.NullReferenceException: Object reference not set to an instance of an object
  at Sharpnado.Presentation.Forms.CustomViews.Tabs.BottomTabItem.UpdateTextVisibility () [0x00033] in D:\Dev\Sharpnado\src\Xamarin-Forms-Practices\Sharpnado.Presentation.Forms\Sharpnado.Presentation.Forms\CustomViews\Tabs\BottomTabItem.xaml.cs:86
  at Sharpnado.Presentation.Forms.CustomViews.Tabs.BottomTabItem.OnPropertyChanged (System.String propertyName) [0x00017] in D:\Dev\Sharpnado\src\Xamarin-Forms-Practices\Sharpnado.Presentation.Forms\Sharpnado.Presentation.Forms\CustomViews\Tabs\BottomTabItem.xaml.cs:72
  at Xamarin.Forms.BindableObject.SetValueActual (Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindableObject+BindablePropertyContext context, System.Object value, System.Boolean currentlyApplying, Xamarin.Forms.Internals.SetValueFlags attributes, System.Boolean silent) [0x00114] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:461
  at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, Xamarin.Forms.Internals.SetValueFlags attributes, Xamarin.Forms.BindableObject+SetValuePrivateFlags privateAttributes) [0x00173] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:397
  at Xamarin.Forms.BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value, System.Boolean fromStyle, System.Boolean checkAccess) [0x00042] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:334
  at Xamarin.Forms.BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value, System.Boolean fromStyle) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:321
  at Xamarin.Forms.Setter.Apply (Xamarin.Forms.BindableObject target, System.Boolean fromStyle) [0x000ba] in D:\a\1\s\Xamarin.Forms.Core\Setter.cs:75
  at Xamarin.Forms.Style.ApplyCore (Xamarin.Forms.BindableObject bindable, Xamarin.Forms.Style basedOn) [0x0001e] in D:\a\1\s\Xamarin.Forms.Core\Style.cs:137
  at Xamarin.Forms.Style.Xamarin.Forms.IStyle.Apply (Xamarin.Forms.BindableObject bindable) [0x0002b] in D:\a\1\s\Xamarin.Forms.Core\Style.cs:98
  at Xamarin.Forms.MergedStyle.SetStyle (Xamarin.Forms.IStyle implicitStyle, System.Collections.Generic.IList`1[T] classStyles, Xamarin.Forms.IStyle style) [0x000f8] in D:\a\1\s\Xamarin.Forms.Core\MergedStyle.cs:185
  at Xamarin.Forms.MergedStyle.set_ImplicitStyle (Xamarin.Forms.IStyle value) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\MergedStyle.cs:85
  at Xamarin.Forms.MergedStyle.OnImplicitStyleChanged () [0x00038] in D:\a\1\s\Xamarin.Forms.Core\MergedStyle.cs:124
  at Xamarin.Forms.MergedStyle.<RegisterImplicitStyles>b__30_0 (Xamarin.Forms.BindableObject bindable, System.Object oldvalue, System.Object newvalue) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\MergedStyle.cs:139
  at Xamarin.Forms.BindableObject.SetValueActual (Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindableObject+BindablePropertyContext context, System.Object value, System.Boolean currentlyApplying, Xamarin.Forms.Internals.SetValueFlags attributes, System.Boolean silent) [0x00120] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:463
  at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, Xamarin.Forms.Internals.SetValueFlags attributes, Xamarin.Forms.BindableObject+SetValuePrivateFlags privateAttributes) [0x00173] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:397
  at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, Xamarin.Forms.Internals.SetValueFlags attributes) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:343
  at Xamarin.Forms.Element.OnResourceChanged (Xamarin.Forms.BindableProperty property, System.Object value) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Element.cs:625
  at Xamarin.Forms.Element.OnSetDynamicResource (Xamarin.Forms.BindableProperty property, System.String key) [0x00020] in D:\a\1\s\Xamarin.Forms.Core\Element.cs:461
  at Xamarin.Forms.BindableObject.SetDynamicResource (Xamarin.Forms.BindableProperty property, System.String key, System.Boolean fromStyle) [0x00066] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:308
  at Xamarin.Forms.BindableObject.SetDynamicResource (Xamarin.Forms.BindableProperty property, System.String key) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:289
  at Xamarin.Forms.MergedStyle.RegisterImplicitStyles () [0x00044] in D:\a\1\s\Xamarin.Forms.Core\MergedStyle.cs:141
  at Xamarin.Forms.MergedStyle..ctor (System.Type targetType, Xamarin.Forms.BindableObject target) [0x0001f] in D:\a\1\s\Xamarin.Forms.Core\MergedStyle.cs:31
  at Xamarin.Forms.NavigableElement..ctor () [0x00011] in D:\a\1\s\Xamarin.Forms.Core\Shell\NavigableElement.cs:23
  at Xamarin.Forms.VisualElement..ctor () [0x00059] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:269
  at Xamarin.Forms.View..ctor () [0x0000b] in D:\a\1\s\Xamarin.Forms.Core\View.cs:75
  at Xamarin.Forms.Layout..ctor () [0x00028] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:71
  at Xamarin.Forms.TemplatedView..ctor () <0x10f1d3350 + 0x0004a> in <8e9ab226c9a54dbdb9366a1fb41e66e3>:0
  at Xamarin.Forms.ContentView..ctor () <0x10f1d3130 + 0x0004a> in <8e9ab226c9a54dbdb9366a1fb41e66e3>:0
  at Sharpnado.Presentation.Forms.CustomViews.Tabs.TabItem..ctor () [0x00000] in D:\Dev\Sharpnado\src\Xamarin-Forms-Practices\Sharpnado.Presentation.Forms\Sharpnado.Presentation.Forms\CustomViews\Tabs\TabItem.cs:30
  at Sharpnado.Presentation.Forms.CustomViews.Tabs.TabTextItem..ctor () <0x10f1d2cc0 + 0x0004a> in <622e7be5f35e46eeb5a36ea1a647426c>:0
  at Sharpnado.Presentation.Forms.CustomViews.Tabs.BottomTabItem..ctor () [0x00000] in D:\Dev\Sharpnado\src\Xamarin-Forms-Practices\Sharpnado.Presentation.Forms\Sharpnado.Presentation.Forms\CustomViews\Tabs\BottomTabItem.xaml.cs:32
  at XamFormsSample.Views.MainPage.InitializeComponent () [0x00034] in /Users/Shared/src/XamFormsSample/XamFormsSample/obj/Debug/netstandard2.0/Views/MainPage.xaml.g.cs:30
  at XamFormsSample.Views.MainPage..ctor () [0x00028] in /Users/Shared/src/XamFormsSample/XamFormsSample/Views/MainPage.xaml.cs:21
  at XamFormsSample.App..ctor () [0x0000f] in /Users/Shared/src/XamFormsSample/XamFormsSample/App.xaml.cs:15
  at XamFormsSample.iOS.AppDelegate.FinishedLaunching (UIKit.UIApplication app, Foundation.NSDictionary options) [0x0000e] in /Users/Shared/src/XamFormsSample/XamFormsSample.iOS/AppDelegate.cs:30
  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/13.6.0.12/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/13.6.0.12/src/Xamarin.iOS/UIKit/UIApplication.cs:65
  at XamFormsSample.iOS.Application.Main (System.String[] args) [0x00001] in /Users/Shared/src/XamFormsSample/XamFormsSample.iOS/Main.cs:17

Screenshots (if applicable)

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions