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

VS2022中新建MAUI项目执行dotnet watch时出现错误

解决dotnet watch启动MAUI项目时的ArgumentNullException错误

问题分析

报错核心原因是项目的launchSettings.json配置文件存在异常,导致dotnet watch读取默认启动配置时找不到有效key,触发空引用异常。

解决步骤

  • 检查并修复Properties/launchSettings.json
    打开项目根目录下的Properties/launchSettings.json,确保profiles节点下的所有配置项格式完整,没有空属性值或缺失必填字段(比如commandName)。如果文件格式混乱,直接替换为MAUI项目默认配置:

    {
      "profiles": {
        "Windows Machine": {
          "commandName": "Project",
          "nativeDebugging": false
        },
        "Android": {
          "commandName": "Android",
          "launchBrowser": false,
          "launchUrl": "https://localhost:5001",
          "environmentVariables": {
            "ASPNETCORE_ENVIRONMENT": "Development"
          },
          "dotnetRunMessages": true,
          "hotReloadProfile": "android"
        },
        "iOS": {
          "commandName": "iOS",
          "launchBrowser": false,
          "launchUrl": "https://localhost:5001",
          "environmentVariables": {
            "ASPNETCORE_ENVIRONMENT": "Development"
          },
          "dotnetRunMessages": true,
          "hotReloadProfile": "ios"
        }
      }
    }
    
  • 指定启动配置运行dotnet watch
    直接在命令中指定具体的启动配置,跳过默认配置读取步骤:

    dotnet watch run --launch-profile "Windows Machine"
    

    注意替换引号内的名称为你项目中实际存在的启动配置名。

  • 清理项目缓存
    删除项目目录下的bin和obj文件夹,重新生成项目后再执行dotnet watch命令。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.26 15:06:13