You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

WinUI3欢迎屏项目单元测试抛出异常的解决方案咨询

WinUI 3欢迎屏项目单元测试异常解决求助

我有一个WinUI 3欢迎屏项目,运行正常,但执行单元测试函数时会抛出异常,现寻求解决办法。当前ViewModel中创建了Frame对象ContentFrame以绑定View中的Frame控件,也接受将Frame移出ViewModel的解决方案。

单元测试代码

[TestClass()]
public class WelcomeScreenPageViewModelTests
{
    [TestMethod()]
    public void WelcomeScreenPageViewModelTest()
    {
        WelcomeScreenPage welcomeScreenPage = new WelcomeScreenPage();
        WelcomeScreenPageViewModel _viewModel = new WelcomeScreenPageViewModel(welcomeScreenPage);// 抛出异常

        Assert.AreEqual(_viewModel.IsCheckBoxVisible, false);
        Assert.AreEqual(_viewModel.IsBackButtonVisible, false);
        Assert.AreEqual(_viewModel.NextButtonText, "Next");  
        Assert.AreEqual(_viewModel.CurrentPageIndex, 0);
    }
} 

ViewModel代码

public class WelcomeScreenPageViewModel : ObservableObject
{
    private WelcomeScreenPage welcomeScreenPage;

    public WelcomeScreenPageViewModel(WelcomeScreenPage welcomeScreenPage)
    {
        this.welcomeScreenPage = welcomeScreenPage;
    }

    public Frame ContentFrame = new();  // 抛出异常
}

View代码

<Frame x:Name="NavigationFrame" Content="{x:Bind ViewModel.ContentFrame,Mode=TwoWay}" />

异常信息

  • 尝试实例化Frame对象时抛出System.Runtime.InteropServices.COMException,错误提示为“类未注册”
  • 调用堆栈显示异常源自WinRT.Runtime内部调用及Frame的构造函数

项目源码已提供。

内容的提问来源于stack exchange,提问作者Ming

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 05:11:06