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

Visual Studio 2022调试单元测试时Edit and Continue因越界读取不可用

调试单元测试时出现"Read out of bounds"错误,断点无法生效

问题重现步骤

  • 打开项目并启动测试资源管理器;
  • 选择任意测试进行调试;
  • 工具栏下方出现Read out of bounds错误提示,测试中的断点无法生效。

已尝试的无效操作

  • 将Visual Studio从17.3.3升级至17.3.6;
  • 修复Visual Studio。

堆栈跟踪信息

StreamJsonRpc.RemoteInvocationException: Read out of bounds.
at StreamJsonRpc.JsonRpc.d__1431.MoveNext() --- End of stack trace from previous location where exception was thrown ---    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)    at Microsoft.CodeAnalysis.EditAndContinue.RemoteEditAndContinueServiceProxy.<>c__DisplayClass5_0.<b__0>d.MoveNext() --- End of stack trace from previous location where exception was thrown ---    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)    at Microsoft.CodeAnalysis.Remote.BrokeredServiceConnection1.d__201.MoveNext() RPC server exception: System.BadImageFormatException: Read out of bounds.       at System.Reflection.Throw.OutOfBounds()       at System.Reflection.Metadata.Ecma335.CustomDebugInformationTableReader..ctor(Int32 numberOfRows, Boolean declaredSorted, Int32 hasCustomDebugInformationRefSize, Int32 guidHeapRefSize, Int32 blobHeapRefSize, MemoryBlock containingBlock, Int32 containingBlockOffset)       at System.Reflection.Metadata.MetadataReader.InitializeTableReaders(MemoryBlock metadataTablesMemoryBlock, HeapSizes heapSizes, Int32[] rowCounts, Int32[] externalRowCountsOpt)       at System.Reflection.Metadata.MetadataReader..ctor(Byte* metadata, Int32 length, MetadataReaderOptions options, MetadataStringDecoder utf8Decoder, Object memoryOwner)       at System.Reflection.Metadata.MetadataReaderProvider.GetMetadataReader(MetadataReaderOptions options, MetadataStringDecoder utf8Decoder)       at Microsoft.CodeAnalysis.Debugging.DebugInformationReaderProvider.Portable.CreateEditAndContinueMethodDebugInfoReader()       at Microsoft.CodeAnalysis.EditAndContinue.CommittedSolution.<>c__DisplayClass15_0.<b__0>d.MoveNext()    --- End of stack trace from previous location where exception was thrown ---       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)       at Microsoft.CodeAnalysis.EditAndContinue.CommittedSolution.d__15.MoveNext()    --- End of stack trace from previous location where exception was thrown ---       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)       at Microsoft.CodeAnalysis.EditAndContinue.EditAndContinueWorkspaceService.d__10.MoveNext()    --- End of stack trace from previous location where exception was thrown ---       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)       at Microsoft.CodeAnalysis.EditAndContinue.RemoteEditAndContinueService.<>c__DisplayClass6_0.<b__0>d.MoveNext()    --- End of stack trace from previous location where exception was thrown ---       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)       at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.<>c__DisplayClass10_01.<g__TryFastGetSolutionAndRunAsync|0>d.MoveNext()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.d__101.MoveNext()    --- End of stack trace from previous location where exception was thrown ---       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)       at Microsoft.CodeAnalysis.Remote.BrokeredServiceBase.d__111.MoveNext()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.CodeAnalysis.Remote.BrokeredServiceBase.d__14`1.MoveNext()

可能的解决方法

1. 清理项目输出文件

  • 手动删除项目的bin和obj文件夹;
  • 重新生成整个解决方案,确保生成过程无错误。

2. 禁用"编辑并继续"功能

从堆栈跟踪看错误与EditAndContinue模块直接相关,可尝试关闭该功能:

  • 打开Visual Studio选项:工具 -> 选项 -> 调试 -> 常规;
  • 取消勾选启用编辑并继续选项;
  • 重启Visual Studio后重新调试测试。

3. 检查项目目标框架兼容性

确保测试项目的目标框架与主项目一致,且兼容当前Visual Studio版本;若使用.NET Core/.NET 5+,尝试切换到稳定版本的框架。

4. 重置Visual Studio设置

  • 打开命令提示符,运行命令:devenv /ResetSettings;
  • 重启Visual Studio,重新配置调试相关设置。

5. 检查测试项目的引用

确认测试项目引用的程序集无损坏,可尝试移除并重新添加引用;若使用NuGet包,更新所有NuGet包到最新稳定版,或尝试回退到之前可正常调试的版本。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.16 17:31:04