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

Visual Studio 2019调试NUnit测试时异常终止并抛出DLL错误

问题描述

在Visual Studio 2019中调试NUnit测试用例时,调试启动后突然终止,抛出以下错误:

引发异常: 'System.BadImageFormatException' in nunit.engine.core.dll
引发异常: 'NUnit.Engine.NUnitEngineException' in nunit.engine.core.dll
引发异常: 'NUnit.Engine.NUnitEngineException' in NUnit3.TestAdapter.dll
'testhost.net452.exe' (CLR v4.0.30319: Domain 4): 已卸载 'C:\WINDOWS\Microsoft.Net\assembly\GAC_64\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'
'testhost.net452.exe' (CLR v4.0.30319: domain-e0e63c75-Visa.CorpTools.Automation.VAM.dll): 已卸载 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll'
The thread 0x1af8 has exited with code 0 (0x0).
引发异常: 'System.ObjectDisposedException' in System.dll
The thread 0x114c has exited with code 0 (0x0).
The thread 0x1c20 has exited with code 0 (0x0).
The program '[13948] testhost.net452.exe' has exited with code 0 (0x0).
解决方案
  • 统一目标架构:
    1. 右键解决方案→属性→配置属性→配置,确保所有项目(含测试项目)的平台目标一致(如统一设为x64或x86)。
    2. 右键测试项目→属性→生成,确认平台目标与解决方案配置匹配,按需勾选/取消“首选32位”选项。
  • 匹配NNUit包版本:
    打开NuGet包管理器,更新NUnit、NUnit3TestAdapter至最新兼容版本,保证两者版本对应(如NUnit 3.x适配NUnit3TestAdapter 4.x系列)。
  • 清理重建项目:
    点击菜单栏“生成”→“清理解决方案”,再执行“重新生成解决方案”,同时手动删除项目bin、obj目录下的旧编译文件。
  • 调整测试运行器架构:
    在Visual Studio的“测试”菜单→“测试设置”→“默认处理器架构”,选择与项目匹配的架构类型。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.25 20:24:23