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 4568795b1fef..4f45299e2b7c 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellRenderer.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellRenderer.cs @@ -364,7 +364,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 e686fe7005d3..34044b202db1 100644 --- a/src/Controls/src/Core/Handlers/Shell/Windows/ShellView.cs +++ b/src/Controls/src/Core/Handlers/Shell/Windows/ShellView.cs @@ -207,6 +207,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 9b2c887e8a1f..020969604cc4 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(() => {