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

VS2019 C# Selenium项目运行报Failed to read descriptor from node connection错误如何解决

问题背景

在Visual Studio Code 2019中运行C# Selenium程序时触发报错:Failed to read descriptor from node connection: A device attached to the system is not functioning。
运行表现:程序启动浏览器后,会弹出数秒的Windows Defender Antivirus wants to reset your settings提示,控制台打印上述报错后程序终止运行。
已知触发逻辑:该问题由Chrome尝试读取当前处于挂起状态的USB设备属性触发。

已尝试无效的排查方案
  • 确认浏览器版本为最新,且无待安装的Windows更新
  • 拔下电脑所有USB设备后重新运行程序,无改善
  • 尝试在访问的URL前添加executable_path=r参数,无效
  • 访问chrome://flags页面查找Enable new USB backend option开关,未找到该选项及任何USB相关配置项
现有测试代码
class EntryPoint
{
    static void Main()
    {
        IWebDriver driver = new ChromeDriver();
        driver.Navigate().GoToUrl("https://testing.todorvachev.com/");
        Thread.Sleep(5000);
        driver.Quit();
    }
}
可行解决方案

方案1:添加Chrome禁用USB检测启动参数

初始化ChromeDriver时传入配置参数,主动禁用USB设备检测逻辑,修改后代码如下:

class EntryPoint
{
    static void Main()
    {
        ChromeOptions options = new ChromeOptions();
        // 禁用USB设备检测,规避USB挂起设备读取报错
        options.AddArgument("--disable-usb-detection");
        // 可选:规避Windows Defender进程拦截
        options.AddArgument("--no-sandbox");
        IWebDriver driver = new ChromeDriver(options);
        driver.Navigate().GoToUrl("https://testing.todorvachev.com/");
        Thread.Sleep(5000);
        driver.Quit();
    }
}

方案2:校验Chrome与ChromeDriver版本匹配

Chrome和对应ChromeDriver的大版本号必须完全一致,若版本不匹配会出现底层通信异常,可前往Chrome设置的「关于Chrome」页面查看当前浏览器版本,下载对应版本的ChromeDriver替换现有文件即可。

方案3:添加Windows Defender排除项

将Chrome进程、ChromeDriver执行文件、你的C#程序编译目录加入Windows Defender的病毒和威胁防护排除列表,避免安全软件拦截Selenium与浏览器的进程通信。

方案4:使用无头模式调试

本地调试时可开启Chrome无头模式,无需加载浏览器UI界面,可规避安全弹窗对进程的干扰,在ChromeOptions中添加参数--headless=new即可启用新版无头模式。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.29 14:09:02