diff --git a/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellRenderer.cs b/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellRenderer.cs index 059e7a91a15a..1774f3502664 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellRenderer.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellRenderer.cs @@ -366,7 +366,7 @@ void SetupCurrentShellItem() { if (Shell.CurrentItem == null) { - return; + throw new InvalidOperationException($"Content not found for active {Shell}. Title: {Shell.Title}. Route: {Shell.Route}."); } else if (_currentShellItemRenderer == null) { diff --git a/src/Controls/src/Core/Handlers/Shell/Windows/ShellView.cs b/src/Controls/src/Core/Handlers/Shell/Windows/ShellView.cs index eb6f4284e626..5bf6ab47fa0d 100644 --- a/src/Controls/src/Core/Handlers/Shell/Windows/ShellView.cs +++ b/src/Controls/src/Core/Handlers/Shell/Windows/ShellView.cs @@ -193,6 +193,12 @@ public override bool Equals(object obj) => internal void SwitchShellItem(ShellItem newItem, bool animate = true) { + if (newItem is null) + throw new InvalidOperationException("Active Shell Item not set. Have you added any Shell Items to your Shell?"); + + if (newItem.CurrentItem is null) + throw new InvalidOperationException($"Content not found for active {newItem}. Title: {newItem.Title}. Route: {newItem.Route}."); + var navItems = FlyoutItems.OfType(); // Implicit items aren't items that are surfaced to the user diff --git a/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.cs b/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.cs index f1a8fba6e7bc..43648d3f58bc 100644 --- a/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.cs +++ b/src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.cs @@ -1139,6 +1139,23 @@ await CreateHandlerAndAddToWindow(shell, _ => }); } +#if !ANDROID // On Android, the exception causes the app to terminate, resulting in a device test failure. + [Fact(DisplayName = "Initialize Empty Shell Throws InvalidOperationException")] + public async Task InitializeEmptyShellThrowsInvalidOperationException() + { + SetupBuilder(); + var shell = new Shell(); + + await Assert.ThrowsAsync(async () => + { + await CreateHandlerAndAddToWindow(shell, (handler) => + { + return Task.CompletedTask; + }); + }); + } +#endif + protected Task CreateShellAsync(Action action) => InvokeOnMainThreadAsync(() => {