【问题标题】:Unpackaged WinUI3 app crashes when calling Bootstrap.Initialize()调用 Bootstrap.Initialize() 时未打包的 WinUI3 应用程序崩溃
【发布时间】:2021-12-29 11:38:20
【问题描述】:

我有一个 WinUI3 应用,我想将其部署为未打包的应用,即不使用 MSIX 打包格式的应用。

我按照此处给出的说明进行操作:Instructions for unpackaged C# WinUI 3 apps,并且运行良好。我可以启动在 bin 文件夹中创建的 exe 文件(调试或发布)或使用“未打包”配置文件调试应用程序。

我尝试的下一件事是在运行时引用 Windows App SDK 以使用它提供的功能。这不起作用,即应用程序崩溃或更准确地说只是停止。

我所做的是按照以下步骤操作:Advanced tutorial: Build and deploy an unpackaged app that uses the Windows App SDK

在他们的示例中,他们使用具有此启动代码的控制台应用程序,您可以在他们的代码中看到对 Bootstrap.Initialize() 的调用:

namespace DynamicDependenciesTest
{
    class Program
    {
        static void Main(string[] args)
        {
            Bootstrap.Initialize(0x00010000); // Call wrapper that enables the Windows App SDK APIs
            Console.WriteLine("Hello World!");

            // Release the DDLM and clean up.
            Bootstrap.Shutdown();
        }
    }
}

在我的 WinUI3 应用程序中,我将对 Bootstrap.Initialize() 的调用插入到 App 类的构造函数中。 但是,一旦执行了调用Initialize 的行,应用程序就会停止,没有可见的异常。 以下两个实现都显示相同的行为。

版本 1:

    /// <summary>
    /// Initializes the singleton application object.  This is the first line of authored code
    /// executed, and as such is the logical equivalent of main() or WinMain().
    /// </summary>
    public App()
    {
        this.InitializeComponent();            

        Bootstrap.Initialize(0x00010000); // --> application stops after this line
    }

版本 2:

    /// <summary>
    /// Initializes the singleton application object.  This is the first line of authored code
    /// executed, and as such is the logical equivalent of main() or WinMain().
    /// </summary>
    public App()
    {
        this.InitializeComponent();

        try
        {
            int hresult;
            bool flag = Bootstrap.TryInitialize(0x00010000, out hresult); // --> application stops after this line
        }
        catch (Exception e)
        {

        }
    }

有人知道这种行为的可能原因吗?
WinUI3 项目引用了“Microsoft.WindowsAppSDK”Nuget 包,我还在我的系统上安装了Windows App SDK(稳定版 1)。

这是我的项目文件的第一部分:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net5.0-windows10.0.19041</TargetFramework>
    <TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
    <RootNamespace>Test.UI</RootNamespace>
    <ApplicationManifest>app.manifest</ApplicationManifest>
    <Platforms>x86;x64;arm64</Platforms>
    <RuntimeIdentifiers>win10-x86;win10-x64;win10-arm64</RuntimeIdentifiers>
    <PublishProfile>win10-$(Platform).pubxml</PublishProfile>
    <UseWinUI>true</UseWinUI>
    <ApplicationIcon>Resources\TASKL.ICO</ApplicationIcon>
    <EnableDefaultPageItems>false</EnableDefaultPageItems>
    <EnablePreviewMsixTooling>true</EnablePreviewMsixTooling>
    <WindowsPackageType>None</WindowsPackageType> // unpackaged
  </PropertyGroup>

【问题讨论】:

    标签: c# winui-3 windows-app-sdk


    【解决方案1】:

    您无需引导您的应用。 None 就足够了。它会自动进行引导。

    也许看看https://github.com/microsoft/WindowsAppSDK/discussions/1935 或者更确切地说是https://github.com/microsoft/WindowsAppSDK/discussions/1933。如果您随时安装了 Microsoft Store 中的“WinUI 3 Controls Gallery”应用程序,则存在错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多