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

Visual Studio 2022中Diagnostic analyzer runner内部错误修复问询

问题

使用Visual Studio 2022(17.4.4)开发.NET 6 C#项目时,遇到以下代码分析异常:

  1. 运行代码分析后立即提示「Code analysis completed for 'projectname'」,但未显示任何警告或错误
  2. 闲置VS 2-3分钟后,弹出错误栏:「Feature 'Diagnostic analyzer runner' is currently unavailable due to an internal error. [Show Stack Trace]」
  3. 点击查看堆栈跟踪得到以下信息:
StreamJsonRpc.RemoteInvocationException: An item with the same key has already been added.
   at StreamJsonRpc.JsonRpc.<InvokeCoreAsync>d__143`1.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.BrokeredServiceConnection`1.<TryInvokeAsync>d__18`1.MoveNext()
RPC server exception:
System.ArgumentException: An item with the same key has already been added.
      at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
      at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
      at Microsoft.CodeAnalysis.RemoveUnnecessarySuppressions.AbstractRemoveUnnecessaryInlineSuppressionsDiagnosticAnalyzer.<ProcessSuppressMessageAttributesAsync>d__25.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.RemoveUnnecessarySuppressions.AbstractRemoveUnnecessaryInlineSuppressionsDiagnosticAnalyzer.<AnalyzeAsync>d__16.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.Diagnostics.Extensions.<>c__DisplayClass9_0.<<GetPragmaSuppressionAnalyzerDiagnosticsAsync>g__AnalyzeDocumentAsync|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.Diagnostics.Extensions.<GetPragmaSuppressionAnalyzerDiagnosticsAsync>d__9.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.Diagnostics.Extensions.<GetAnalysisResultAsync>d__7.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.Diagnostics.DiagnosticComputer.<AnalyzeAsync>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.Remote.Diagnostics.DiagnosticComputer.<GetDiagnosticsAsync>d__9.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.RemoteDiagnosticAnalyzerService.<>c__DisplayClass4_0.<<CalculateDiagnosticsAsync>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__DisplayClass7_0`1.<<RunWithSolutionAsync>g__ProcessSolutionAsync|1>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.<RunWithSolutionAsync>d__7`1.MoveNext()
   --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
      at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.<RunWithSolutionAsync>d__7`1.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.<RunWithSolutionAsync>d__11`1.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.RemoteDiagnosticAnalyzerService.<CalculateDiagnosticsAsync>d__4.MoveNext()

修复/排查步骤

  • 检查重复的SuppressMessage属性:堆栈指向AbstractRemoveUnnecessaryInlineSuppressionsDiagnosticAnalyzer,说明项目中存在重复的[SuppressMessage]特性(同一代码元素上多次应用了针对同一规则的抑制)。全局搜索项目中的[SuppressMessage],排查是否有重复定义,比如同一方法、类上多次添加了相同Category和CheckId的抑制特性,删除重复项即可。
  • 更新Visual Studio版本:当前使用的17.4.4是较旧的VS2022版本,这个分析器的重复键问题在后续更新中已被修复。直接升级到最新的VS2022稳定版,可解决此类已知BUG。
  • 清理VS缓存:删除VS的缓存文件,路径一般为:
    • %LOCALAPPDATA%\Microsoft\VisualStudio\17.0_<随机字符>\ComponentModelCache
    • %USERPROFILE%\AppData\Local\Temp\VisualStudioTestExplorerExtensions
      清理后重启VS,再尝试运行代码分析。
  • 禁用特定分析器:临时禁用RemoveUnnecessarySuppressions分析器,在项目文件(.csproj)中添加以下配置:
<PropertyGroup>
  <AnalyzerDisableRules>IDE0079</AnalyzerDisableRules>
</PropertyGroup>

或者在VS的「项目属性→代码分析→规则集」中,找到「IDE0079: Remove unnecessary suppression」并禁用,验证是否能正常运行代码分析。

  • 创建空白项目测试:新建一个空的.NET 6 C#项目,运行代码分析,确认是否出现同样问题。如果空白项目正常,说明原项目存在特定代码或配置问题,可逐步迁移代码排查根源。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.03 14:10:27