You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

C++ WinRT/WinUI-3运行时启动/关闭错误来源排查求助

WinUI 3 C++ WinRT项目启动及关闭时异常排查

问题概述

基于VS2022 V17.13.6的「Blank App, Packaged (WinUI 3 in Desktop)」模板创建项目,仅修改XAML布局(替换为Grid的4列3行布局,中间单元格放置TextBlock和Slider),未改动后置代码及App类,但启动时持续抛出内部组件错误,关闭窗口时触发线程异常;添加后置逻辑时仅出现Windows内部调用栈异常,无自定义代码线索。更换多个VS版本(含预览版17.14)后问题依旧。

运行环境:Windows 11 Home,Surface Pro+,x64构建配置

启动时错误日志

onecore\internal\sdk\inc\wil/resource.h(955)\dwmcorei.dll!00007FF9885571B6: (caller: 00007FF98855F285) ReturnNt(1) tid(2e6c) C0000022 onecoreuap\windows\frameworkudk\warppal.cpp(783)\Microsoft.Internal.FrameworkUdk.dll!00007FFA142E9308: (caller: 00007FFA14282FAD) ReturnHr(1) tid(68a0) 80004002 No such interface supported
onecoreuap\windows\frameworkudk\warppal.cpp(783)\Microsoft.Internal.FrameworkUdk.dll!00007FFA142E9308: (caller: 00007FFA14282FAD) ReturnHr(2) tid(68a0) 80004002 No such interface supported
Microsoft.UI.Xaml.dll!00007FF973DB41F2: 80070057 - E_INVALIDARG
Microsoft.UI.Xaml.dll!00007FF973DB41F2: 80070057 - E_INVALIDARG
Microsoft.UI.Xaml.dll!00007FF973DB41F2: 80070057 - E_INVALIDARG
onecoreuap\windows\frameworkudk\warppal.cpp(783)\Microsoft.Internal.FrameworkUdk.dll!00007FFA142E9308: (caller: 00007FFA14282FAD) ReturnHr(3) tid(2e6c) 80004002 No such interface supported

关闭窗口时错误日志

Microsoft.UI.Xaml.dll!00007FF979804913: 8001010E - RPC_E_WRONG_THREAD

相关代码文件

MainWindow.idl

namespace SliderTest
{
    [default_interface]
    runtimeclass MainWindow : Microsoft.UI.Xaml.Window
    {
        MainWindow();
    }
}

MainWindow.h

#pragma once

#include "MainWindow.g.h"

namespace winrt::SliderTest::implementation
{
    struct MainWindow : MainWindowT<MainWindow>
    {
        MainWindow()
        {
            // Xaml objects should not call InitializeComponent during construction.
            // See https://github.com/microsoft/cppwinrt/tree/master/nuget#initializecomponent
        }

    };
}

namespace winrt::SliderTest::factory_implementation
{
    struct MainWindow : MainWindowT<MainWindow, implementation::MainWindow>
    {
    };
}

MainWindow.cpp

#include "pch.h"
#include "MainWindow.xaml.h"
#if __has_include("MainWindow.g.cpp")
#include "MainWindow.g.cpp"
#endif

using namespace winrt;
using namespace Microsoft::UI::Xaml;

// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.

namespace winrt::SliderTest::implementation
{
}

MainWindow.xaml

<?xml version="1.0" encoding="utf-8"?>
<Window
    x:Class="SliderTest.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:SliderTest"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    Title="SliderTest">

    <Grid HorizontalAlignment="Center" VerticalAlignment="Center">
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="50"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="120"/>
            <ColumnDefinition Width="120"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <TextBlock Grid.Row="1" Grid.Column="1" VerticalAlignment="Center"
                   HorizontalAlignment="Right">Width: </TextBlock>
        <Slider x:Name="SliderWidth" Minimum="9" Maximum="31"
                    Width="100" StepFrequency="1" Value="9"
                    VerticalAlignment="Center" HorizontalAlignment="Center"
                    Grid.Row="1" Grid.Column="2"/>
    </Grid>
</Window>

排查建议

  1. 修复系统组件

    • 运行sfc /scannowDISM /Online /Cleanup-Image /RestoreHealth命令修复系统文件,这类内部组件错误常与系统框架损坏相关。
    • 确保Windows 11更新至最新版本,WinUI 3依赖的系统组件可能随系统更新修复。
  2. 验证NuGet包兼容性

    • 检查项目中Microsoft.UI.Xaml NuGet包版本,尝试回退到2.8.x等稳定版本,新版本可能存在兼容性问题。
    • 清理NuGet缓存后重新安装所有依赖包。
  3. 调试窗口初始化线程

    • 在App类中添加窗口创建的调试日志,确认窗口初始化是否在UI线程执行。WinUI 3要求窗口操作必须在UI线程完成,线程调用错误会触发RPC_E_WRONG_THREAD异常。
    • 临时在MainWindow构造函数中手动调用InitializeComponent(),测试是否为XAML加载流程问题。
  4. 排查渲染组件冲突

    • 错误涉及dwmcorei.dll,尝试禁用桌面窗口管理器的透明度、圆角等特效,或在项目中禁用WinUI 3的Acrylic等高级视觉效果,排查渲染组件冲突。
  5. 更新设备驱动

    • 更新Surface Pro的Intel集成显卡驱动至最新版本,WinUI 3的渲染逻辑依赖GPU驱动支持,旧驱动可能引发兼容性问题。

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

火山引擎 最新活动