MAUI 程序启动提示 System.Reflection.TargetInvocationException 错误
背景
MAUI版本:preview4
通过VS2019 preview创建了一个MAUI应用程序,设置了MauiApp1.WinUI3
为启动项目,在启动时,提示如下错误
System.Reflection.TargetInvocationException:“Exception has been thrown by the target of an invocation.”
COMException: 没有注册类 (0x80040154 (REGDB_E_CLASSNOTREG))
解决
参考https://github.com/dotnet/maui/issues/1127
排查方法:
- 安装VS Preview 16.11.0 Preview 1.0。
- 安装
MAUI Check
工具,并通过maui-check
命令,检查MAUI环境是否完整且正确。 - VS下新建
.NET MAUI App
项目。 - 设置
WinUI3 (Package)
项目为启动项。 - 以“本地计算机”为目标,运行项目。