WinUI3 Microsoft.UI.XAML.dll "Source Code Not Available" 调试错误

WinUI3 Microsoft.UI.XAML.dll "Source Code Not Available" error on Debug

我的应用构建良好。但是,尝试以调试模式启动它会导致此错误。这出现在我解决了与缺少“调试符号”相关的错误 similar to the one here (在选项中启用远程符号服务器然后构建导致出现此错误 - 即使在关闭远程符号服务器后这种行为仍然存在选项)。

我在 Visual Studio 2022 上 Windows 11.

使用 WinUI3 项目

seems to suggest the issue was using WPF - but I am not using WPF. I also see a potentially similar issue here,但似乎没有答案。

我什至不确定从哪里开始解决这个问题 - 它似乎是 Visual Studio 问题或 project/solution 配置问题,而不是代码问题。有什么想法吗?

我修好了。我正在查看 Visual Studio 控制台中的输出(在问题中提到的错误发生后停止应用程序之后),我看到了这个:

Exception thrown at 0x00007FFD41D4466C (KernelBase.dll) in EmailClient.exe: WinRT originate error - 0x80004005 : 'WinUI: Error creating second Desktop Window on the current process. No more than one Desktop Window is allowed per process.'. onecore\com\combase\winrt\error\restrictederror.cpp(1017)\combase.dll!00007FFD43EAA21E: (caller: 00007FFD43D9A2F3) ReturnHr(2) tid(5e98) 8007007E The specified module could not be found.

然后我搜索了我的项目,发现在初始化一个 属性。我删除了它(将 属性 初始化为 null),现在该应用程序运行正常。不确定这两者是如何相关的......但这可能是由于试图在同一进程上创建多个 windows 而导致的意外行为。 Here is someone else who had the same issue.

如果您打算创建多个 windows(我的不是)并且您想知道如何,then see this thread(过时了几个月...不确定是否截至发布之时,提到的功能是否仍处于预览状态)。