简体   繁体   English

C# .NET MAUI 在视图中导航到页面会引发异常用户未处理的错误

[英]C# .NET MAUI Navigating to page in Views throws Exception User-Unhandled error

C#, .NET and MAUI: When navigating to a page in the Views folder I receive the following Exception error: System.Runtime.InteropServices.COMException: '0x88000FA8'. C#、.NET 和 MAUI:导航到 Views 文件夹中的页面时,我收到以下异常错误:System.Runtime.InteropServices.COMException:'0x88000FA8'。 Exception Error screenshot异常错误截图

This error occurs on the FundsPage of the project, however if I resize the window smaller and try to navigate to the other pages (for example StudentsPage) I encounter the same error.此错误发生在项目的 FundsPage 上,但是如果我将 window 的大小调整为更小并尝试导航到其他页面(例如 StudentPage),我会遇到相同的错误。

I've tested the project on a different windows machine and the same problem occurs.我已经在不同的 windows 机器上测试了该项目,并且出现了同样的问题。

I'm not sure why I'm getting this error.我不确定为什么会收到此错误。 Could this be a bug or something related MAUI?这可能是一个错误或与 MAUI 相关的东西吗?

Navbar.xaml.cs导航栏.xaml.cs

namespace EduCube;

public partial class Navbar : ContentView
{
    public Navbar()
    {
        InitializeComponent();
    }


    private async void mainpageroute(object sender, EventArgs e)
    {

        await Shell.Current.GoToAsync("/DashboardPage");
    }

    private async void teacherpageroute(object sender, EventArgs e)
    {

        await Shell.Current.GoToAsync("/TeachersPage");
    }

    private async void studentpageroute(object sender, EventArgs e)
    {

        await Shell.Current.GoToAsync("/StudentsPage");
    }

    private async void subjectpageroute(object sender, EventArgs e)
    {

        await Shell.Current.GoToAsync("/SubjectsPage");
    }

    private async void fundspageroute(object sender, EventArgs e)
    {

        await Shell.Current.GoToAsync("/FundsPage"); //Exception User-Unhandled error
    }

}

Code Behind: FundsPage.xaml.cs代码隐藏:FundsPage.xaml.cs

namespace EduCube;

public partial class FundsPage : ContentPage
{
    public FundsPage()
    {
        InitializeComponent();
    }
}

AppShell.xaml.cs AppShell.xaml.cs

using EduCube.Views.AddUpdateViews;

namespace EduCube;

public partial class AppShell : Shell
{
    public AppShell()
    {
        InitializeComponent();
        //initialise routes
        Routing.RegisterRoute("DashboardPage", typeof(DashboardPage));
        Routing.RegisterRoute("StudentsPage", typeof(StudentsPage));
        Routing.RegisterRoute("SubjectsPage", typeof(SubjectsPage));
        Routing.RegisterRoute("TeachersPage", typeof(TeachersPage));
        Routing.RegisterRoute("FundsPage", typeof(FundsPage));
        Routing.RegisterRoute("MainPage", typeof(MainPage));
        //initialize add and update pages
        Routing.RegisterRoute(nameof(AddUpdateSubjectPage), typeof(AddUpdateSubjectPage));
    }
}

AppShell.xaml AppShell.xaml

<Shell
    x:Class="EduCube.AppShell"
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:local="clr-namespace:EduCube"
    Shell.FlyoutBehavior="Disabled">
    
    <!--Login Page -->
    <ShellContent
        ContentTemplate="{DataTemplate local:MainPage}"
        Route="MainPage" />
    <!-- Dashboard page -->
    <ShellContent
        ContentTemplate="{DataTemplate local:DashboardPage}"
        Route="DashboardPage" />
    <!-- Teachers page -->
    <ShellContent
        ContentTemplate="{DataTemplate local:TeachersPage}"
        Route="TeachersPage" />
    <!-- Students page -->
    <ShellContent
        ContentTemplate="{DataTemplate local:StudentsPage}"
        Route="StudentsPage" />
    <!-- Subjects page -->
    <ShellContent
        ContentTemplate="{DataTemplate local:SubjectsPage}"
        Route="SubjectsPage" />
    <!-- Funds page -->
    <ShellContent
        ContentTemplate="{DataTemplate local:FundsPage}"
        Route="FundsPage" />
</Shell>

System.Runtime.InteropServices.COMException: '0x88000FA8' System.Runtime.InteropServices.COMException: '0x88000FA8'

System.Runtime.InteropServices.COMException
  HResult=0x88000FA8
  Message=0x88000FA8
  Source=WinRT.Runtime
  StackTrace:
   at WinRT.ExceptionHelpers.<ThrowExceptionForHR>g__Throw|20_0(Int32 hr)
   at Microsoft.Maui.Controls.Handlers.ShellItemHandler.MapTabBarIsVisible(ShellItemHandler handler, ShellItem item)
   at Microsoft.Maui.PropertyMapper.UpdateProperties(IElementHandler viewHandler, IElement virtualView)
   at Microsoft.Maui.Controls.Handlers.ShellItemHandler.SetVirtualView(IElement view)
   at Microsoft.Maui.Controls.Platform.ShellView.CreateShellItemView()
   at Microsoft.Maui.Controls.Platform.ShellView.SwitchShellItem(ShellItem newItem, Boolean animate)
   at Microsoft.Maui.Controls.Element.OnPropertyChanged(String propertyName)
   at Microsoft.Maui.Controls.Shell.OnPropertyChanged(String propertyName)
   at Microsoft.Maui.Controls.BindableObject.SetValueActual(BindableProperty property, BindablePropertyContext context, Object value, Boolean currentlyApplying, SetValueFlags attributes, Boolean silent)
   at Microsoft.Maui.Controls.BindableObject.SetValueCore(BindableProperty property, Object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes)
   at Microsoft.Maui.Controls.ShellNavigationManager.<GoToAsync>d__14.MoveNext()
   at EduCube.Navbar.<fundspageroute>d__5.MoveNext() in C:\Users\hello\source\repos\EduCube2\Components\Navbar.xaml.cs:line 38

I've managed to fix this problem with the FundsPage crashing when navigating to the page.我已经设法解决了在导航到页面时 FundsPage 崩溃的问题。 I did a reset and new installation of Windows 11 OS on my machine.我在我的机器上重新安装了 Windows 11 OS。 I installed Visual Studio Community Preview (17.4.0 Preview 1.0).我安装了 Visual Studio 社区预览版(17.4.0 预览版 1.0)。 During installation of VS I made sure to select the ASP.Net and web development , .NET Multi-platform App UI development and .NET desktop development workloads. During installation of VS I made sure to select the ASP.Net and web development , .NET Multi-platform App UI development and .NET desktop development workloads. I then cloned the repository again and Rebuilt the project and ran it.然后我再次克隆存储库并重建项目并运行它。

If anyone has the same error this solution might or might not work for you.如果有人有同样的错误,这个解决方案可能对你有用,也可能对你不起作用。 In my case it did.就我而言,确实如此。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM