Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[Bug] Shell throws NullRef if improperly configured #8211

Closed
Eilon opened this issue Oct 24, 2019 · 0 comments · Fixed by #8250
Closed

[Bug] Shell throws NullRef if improperly configured #8211

Eilon opened this issue Oct 24, 2019 · 0 comments · Fixed by #8250
Labels
a/shell 🐚 e/2 🕑 2 in-progress This issue has an associated pull request that may resolve it! t/bug 🐛

Comments

@Eilon
Copy link
Contributor

Eilon commented Oct 24, 2019

Description

While I don't expect Shell to work if improperly configured, I don't expect a NullRef in these cases either (NullRef is nearly always invalid if there are no bugs).

Steps to Reproduce

Minimal case where Shell works (good):

            var shell = new Shell();
            var shellContent = new ShellContent();
            shell.Items.Add(shellContent);

            MainPage = shell;

Verbose case where Shell works (good):

            var shell = new Shell();
            var tabBar = new TabBar();
            var tab = new Tab();
            var shellContent = new ShellContent();
            shellContent.Content = new ContentPage() { Content = new Label() { Text = "HI!!!" } };
            tab.Items.Add(shellContent);
            tabBar.Items.Add(tab);
            shell.Items.Add(tabBar);

            MainPage = shell;

But if you "partially" configure Shell, you get NullRef exceptions. For example, add a TabBar with a Tab but no ShellContent (bad):

            var shell = new Shell();
            var tabBar = new TabBar();
            var tab = new Tab();
            tabBar.Items.Add(tab);
            shell.Items.Add(tabBar);

            MainPage = shell;

And you get this:

System.NullReferenceException: 'Object reference not set to an instance of an object.'

 	0xFFFFFFFFFFFFFFFF in System.Diagnostics.Debugger.Mono_UnhandledException_internal	C#
 	0x1 in System.Diagnostics.Debugger.Mono_UnhandledException at /Users/builder/jenkins/workspace/archive-mono/2019-08/android/release/mcs/class/corlib/System.Diagnostics/Debugger.cs:120,4	C#
 	0x33 in Android.Runtime.DynamicMethodNameCounter.45	C#
 	0xB3 in Xamarin.Forms.Platform.Android.ShellSectionRenderer.OnCreateView at D:\a\1\s\Xamarin.Forms.Platform.Android\Renderers\ShellSectionRenderer.cs:150,4	C#
 	0x24 in Android.Support.V4.App.Fragment.n_OnCreateView_Landroid_view_LayoutInflater_Landroid_view_ViewGroup_Landroid_os_Bundle_	C#
 	0x23 in Android.Runtime.DynamicMethodNameCounter.45	C#
 	0xFFFFFFFFFFFFFFFF in Java.Interop.NativeMethods.java_interop_jnienv_call_nonvirtual_void_method_a	C#
 	0x79 in Java.Interop.JniEnvironment.InstanceMethods.CallNonvirtualVoidMethod	C#
 	0x5F in Java.Interop.JniPeerMembers.JniInstanceMethods.InvokeVirtualVoidMethod	C#
 	0x12 in Android.App.Activity.OnStart	C#
 	0x20 in Xamarin.Forms.Platform.Android.FormsAppCompatActivity.OnStart at D:\a\1\s\Xamarin.Forms.Platform.Android\AppCompat\FormsAppCompatActivity.cs:360,4	C#
 	0xA in Android.App.Activity.n_OnStart	C#
 	0x11 in Android.Runtime.DynamicMethodNameCounter.21	C#

Another "partially" configure Shell that causes a NullRef exception: Add a TabBar without a Tab or ShellContent (bad):

            var shell = new Shell();
            var tabBar = new TabBar();
            shell.Items.Add(tabBar);

            MainPage = shell;

And you get this:

System.NullReferenceException: 'Object reference not set to an instance of an object.'

 	0xFFFFFFFFFFFFFFFF in System.Diagnostics.Debugger.Mono_UnhandledException_internal	C#
 	0x1 in System.Diagnostics.Debugger.Mono_UnhandledException at /Users/builder/jenkins/workspace/archive-mono/2019-08/android/release/mcs/class/corlib/System.Diagnostics/Debugger.cs:120,4	C#
 	0x33 in Android.Runtime.DynamicMethodNameCounter.45	C#
 	0xD3 in Xamarin.Forms.Platform.Android.ShellBottomNavViewAppearanceTracker.SetBackgroundColor at D:\a\1\s\Xamarin.Forms.Platform.Android\Renderers\ShellBottomNavViewAppearanceTracker.cs:90,5	C#
 	0x27 in Xamarin.Forms.Platform.Android.ShellBottomNavViewAppearanceTracker.ResetAppearance at D:\a\1\s\Xamarin.Forms.Platform.Android\Renderers\ShellBottomNavViewAppearanceTracker.cs:33,4	C#
 	0xC in Xamarin.Forms.Platform.Android.ShellItemRenderer.ResetAppearance at D:\a\1\s\Xamarin.Forms.Platform.Android\Renderers\ShellItemRenderer.cs:335,47	C#
 	0x12 in Xamarin.Forms.Platform.Android.ShellItemRenderer.Xamarin.Forms.IAppearanceObserver.OnAppearanceChanged at D:\a\1\s\Xamarin.Forms.Platform.Android\Renderers\ShellItemRenderer.cs:41,5	C#
 	0x1A in Xamarin.Forms.Shell.Xamarin.Forms.IShellController.AddAppearanceObserver at D:\a\1\s\Xamarin.Forms.Core\Shell\Shell.cs:203,4	C#
 	0xBC in Xamarin.Forms.Platform.Android.ShellItemRenderer.OnCreateView at D:\a\1\s\Xamarin.Forms.Platform.Android\Renderers\ShellItemRenderer.cs:76,4	C#
 	0x24 in Android.Support.V4.App.Fragment.n_OnCreateView_Landroid_view_LayoutInflater_Landroid_view_ViewGroup_Landroid_os_Bundle_	C#
 	0x23 in Android.Runtime.DynamicMethodNameCounter.45	C#
 	0xFFFFFFFFFFFFFFFF in Java.Interop.NativeMethods.java_interop_jnienv_call_nonvirtual_void_method_a	C#
 	0x79 in Java.Interop.JniEnvironment.InstanceMethods.CallNonvirtualVoidMethod	C#
 	0x5F in Java.Interop.JniPeerMembers.JniInstanceMethods.InvokeVirtualVoidMethod	C#
 	0x12 in Android.App.Activity.OnStart	C#
 	0x20 in Xamarin.Forms.Platform.Android.FormsAppCompatActivity.OnStart at D:\a\1\s\Xamarin.Forms.Platform.Android\AppCompat\FormsAppCompatActivity.cs:360,4	C#
 	0xA in Android.App.Activity.n_OnStart	C#
 	0x11 in Android.Runtime.DynamicMethodNameCounter.21	C#

But if you just create an empty Shell with nothing at all, you get a much nicer exception (good):

            var shell = new Shell();

            MainPage = shell;

You get this nice exception:

System.ArgumentException: 'Active Shell Item not set. Have you added any Shell Items to your Shell?
Parameter name: ShellItem'

 	0xFFFFFFFFFFFFFFFF in System.Diagnostics.Debugger.Mono_UnhandledException_internal	C#
 	0x1 in System.Diagnostics.Debugger.Mono_UnhandledException at /Users/builder/jenkins/workspace/archive-mono/2019-08/android/release/mcs/class/corlib/System.Diagnostics/Debugger.cs:120,4	C#
 	0x33 in Android.Runtime.DynamicMethodNameCounter.45	C#
 	0x80 in Xamarin.Forms.Platform.Android.ShellItemRenderer.OnCreateView at D:\a\1\s\Xamarin.Forms.Platform.Android\Renderers\ShellItemRenderer.cs:70,5	C#
 	0x24 in Android.Support.V4.App.Fragment.n_OnCreateView_Landroid_view_LayoutInflater_Landroid_view_ViewGroup_Landroid_os_Bundle_	C#
 	0x23 in Android.Runtime.DynamicMethodNameCounter.45	C#
 	0xFFFFFFFFFFFFFFFF in Java.Interop.NativeMethods.java_interop_jnienv_call_nonvirtual_void_method_a	C#
 	0x79 in Java.Interop.JniEnvironment.InstanceMethods.CallNonvirtualVoidMethod	C#
 	0x5F in Java.Interop.JniPeerMembers.JniInstanceMethods.InvokeVirtualVoidMethod	C#
 	0x12 in Android.App.Activity.OnStart	C#
 	0x20 in Xamarin.Forms.Platform.Android.FormsAppCompatActivity.OnStart at D:\a\1\s\Xamarin.Forms.Platform.Android\AppCompat\FormsAppCompatActivity.cs:360,4	C#
 	0xA in Android.App.Activity.n_OnStart	C#
 	0x11 in Android.Runtime.DynamicMethodNameCounter.21	C#

Expected Behavior

More consistent and nice exceptions for various incorrectly-configured Shell instances.

Actual Behavior

NullRef thrown from incorrectly-configured Shell instances.

Basic Information

  • Version with issue: Xamarin.Forms 4.3.0
@Eilon Eilon added t/bug 🐛 s/unverified New report that has yet to be verified labels Oct 24, 2019
@pauldipietro pauldipietro added this to New in Triage Oct 24, 2019
@hartez hartez added a/shell 🐚 and removed s/unverified New report that has yet to be verified labels Oct 25, 2019
@hartez hartez added this to To do in Other Ready For Work via automation Oct 25, 2019
@hartez hartez removed this from New in Triage Oct 25, 2019
@hartez hartez added the e/2 🕑 2 label Oct 25, 2019
@samhouts samhouts added the in-progress This issue has an associated pull request that may resolve it! label Nov 2, 2019
@samhouts samhouts added this to In Progress in v4.5.0 Nov 2, 2019
@samhouts samhouts added this to In Progress in Shell Jan 3, 2020
Other Ready For Work automation moved this from To do to Done Jan 6, 2020
v4.5.0 automation moved this from In Progress to Done Jan 6, 2020
Shell automation moved this from In Progress to Done Jan 6, 2020
@samhouts samhouts moved this from Done to In Progress in v4.5.0 Jan 6, 2020
@samhouts samhouts moved this from In Progress to Done in v4.5.0 Jan 6, 2020
@samhouts samhouts added this to In Progress in v4.6.0 Jan 7, 2020
@samhouts samhouts moved this from In Progress to Done in v4.6.0 Jan 7, 2020
@samhouts samhouts removed this from Done in Other Ready For Work May 6, 2020
@samhouts samhouts removed this from Done in Shell May 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a/shell 🐚 e/2 🕑 2 in-progress This issue has an associated pull request that may resolve it! t/bug 🐛
Projects
No open projects
v4.5.0
  
Done
v4.6.0
  
Done
Development

Successfully merging a pull request may close this issue.

3 participants