Skip to content
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

Bug: Exception throw when close admin dashboard #3909

Closed
zyhfish opened this issue Feb 27, 2024 · 3 comments
Closed

Bug: Exception throw when close admin dashboard #3909

zyhfish opened this issue Feb 27, 2024 · 3 comments

Comments

@zyhfish
Copy link
Contributor

zyhfish commented Feb 27, 2024

Reproduce Steps:

  1. build the latest code (up to commit #f017b6b92fd2ab841465f9f5a4f15c9f719c7f73) and install a new instance.
  2. login as super user, open admin dashboard.
  3. click the X button to close the dashboard.

Expected Result:
the dashboard should be closed.

Actually Result:
Exception thrown:
2024-02-27_215756

@sbwalker
Copy link
Member

sbwalker commented Feb 27, 2024

@zyhfish this is a known problem and is caused by Blazor in Static rendering running within Visual Studio. The recommendation from Microsoft is to configure Visual Studio to not break on this type of exception. See this issue: dotnet/aspnetcore#53996

@sbwalker
Copy link
Member

sbwalker commented Feb 27, 2024

@zyhfish so the problem is that even if you catch the exception in code, the NavigationManager will fail to redirect to the desired Url:

using Microsoft.AspNetCore.Components;

namespace Oqtane.Extensions
{
    public static class NavigationManagerExtensions
    {
        public static void NavigateToIgnoreException(this NavigationManager navigationManager, string uri, bool forceLoad = false, bool replace = false)
        {
            try
            {
                navigationManager.NavigateTo(uri, forceLoad, replace);
            }
            catch
            {
                // ignore exception thrown in static rendering within debugger
            }
        }
    }
}

and if you change the AdminContainer.razor to use the extension method:

	private void CloseModal()
	{
		NavigationManager.NavigateToIgnoreException((!string.IsNullOrEmpty(PageState.ReturnUrl)) ? PageState.ReturnUrl : NavigateUrl());
    }

The exception will be ignored - but you will not be redirected to the desired location.

It seems that the only way to deal with this currently is to suppress the error in Visual Studio and then it will work as expected.

@sbwalker
Copy link
Member

Closing as there is no solution in .NET 8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants