Skip to content

Fixed a NullReferenceException when starting application with empty shell on Windows #28879

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Controls/src/Core/Handlers/Shell/Windows/ShellView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,12 @@ public override bool Equals(object obj) =>

internal void SwitchShellItem(ShellItem newItem, bool animate = true)
{
if (newItem is null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the behavior on other platforms? Would be nice to align the behavior and throw the same exception with the same message if possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jsuarezruiz, On Android, the empty Shell throws a similar exception.

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<NavigationViewItemViewModel>();

// Implicit items aren't items that are surfaced to the user
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -819,5 +819,21 @@ AnimatedIcon GetNativeAnimatedIcon(ShellHandler shellHandler)

return animatedIcon;
}

[Fact(DisplayName = "Initialize Empty Shell Throws InvalidOperationException")]
public async Task InitializeEmptyShellThrowsInvalidOperationException()
{
SetupBuilder();

var shell = new Shell();

await Assert.ThrowsAsync<InvalidOperationException>(async () =>
{
await CreateHandlerAndAddToWindow<ShellHandler>(shell, (handler) =>
{
return Task.CompletedTask;
});
});
}
}
}