首页 > 解决方案 > 将 Visual Studio MVC 应用程序调试到 Chrome 时出现“spawn UNKNOWN”错误

问题描述

我正在使用 MVC (Visual Studio) 创建一个网站,当我使用 IIS Express 进行调试时出现错误“spawn unknown”。是什么导致了这个错误,我该如何解决?

这是使用 Visual Studio 2017,但我怀疑这可能与它在我的计算机上的配置方式有关,因为此错误不会在其他计算机上发生。

这是视图:

@model WebApplication4.Models.Customer

@{
    ViewBag.Title = "Index";
}
<h2>Index</h2>

和控制器:

namespace WebApplication4.Controllers
{
    public class CustomerController : Controller
    {
        private ApplicationDbContext _context;

        public CustomerController()
        {
            _context = new ApplicationDbContext();
        }
        // GET: Customer
        public ActionResult Index(int id)
        {
            var customers = _context.Customers.ToList();
           return View(customers);
        }
}

和模型:

namespace WebApplication4.Models
{
    public class Customer
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public string Address { get; set; }
        public Membership MembershipType { get; set; }
    }

    public enum Membership
    {
        REGULAR,
        SILVER,
        GOLD
    };
}

当我使用 IIS Express 调试解决方案时,我没有打开 Chrome 并显示索引页面,而是从 Microsoft Visual Studio 中得到一个弹出框,提示:发生了一个或多个错误。[debugger-for-chrome] 处理“启动”时出错:spawn UNKNOWN

关于“spawn unknown”有很多问题,但没有关于 C# 或 MVC(通常是 node.js 或 php -这里有一个关于 VS 错误的问题,但它是关于打开 .php 扩展文件后出现的弹出窗口。根据到这个答案:错误:产生未知它看起来问题与使用 Chrome 作为网络浏览器有关。但是是否可以将 IIS Express 更改为使用 Chrome 以外的其他东西?

标签: google-chromemodel-view-controller

解决方案


对我来说,这不是特权问题。问题是在我的计算机中,Chrome 安装在两个不同的位置:

C:\Users\[user]\AppData\Local\Google\Chrome\Application\chrome.exe
C:\Program Files (x86)\Google\Chrome\Application\chrome.exe

对于我的 PC,第一个是损坏的可执行文件,它是 64 位的,不知何故它变成了垃圾,不再起作用,所以我设法将 Chrome 32 位重新安装到第二个路径上。无论如何,最终导致两个 Chrome 可执行文件并存。

我完全忘记了还有另一个,并且在 PATH 中添加了第二个,所以我认为 VS 代码没有引用这个的可能性。

因此,在这种情况下,您需要runtimeExecutable在您的 launch.json 中提供,如下所示:

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "chrome",
            "request": "launch",
            "name": "Launch Chrome",
            "url": "https://example.com",
            "runtimeArgs": ["--load-extension=${workspaceFolder}"], 
            "runtimeExecutable": "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe",
        }
    ]
}

推荐阅读