由于内部错误,“诊断分析器运行程序”当前不可用

问题描述 投票:0回答:2

我使用的是 Visual Studio 2022 (17.4.4)。这是一个 .NET 6 C# 项目。

在我的项目上运行代码分析时,我立即收到消息“‘projectname’的代码分析已完成”。不显示代码分析警告或错误。

当我将 Visual Studio 打开几分钟(不执行任何操作)时,2-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()
visual-studio roslyn roslyn-code-analysis
2个回答
3
投票

当您遇到这样的消息时,这是一个错误。因此,您可能无法进行修复。此类错误应报告给 Microsoft。

此错误已报告 https://github.com/dotnet/roslyn/issues/50496

您必须等待修复。


0
投票

我的经历类似(VS 17.7.2)。如果我只是打开一个 .cs 文件而不执行任何操作,错误就会开始出现。一旦它们开始出现,只有关闭 Visual Studio 才能让它们消失。我重新启动VS后等待几分钟后它们会重新出现。我注意到只有当我打开特定的 .cs 文件时才会发生这种情况。

我发现错误是由于一个非常长的字符串连接。我有一条长绳子,看起来像:

string longString = var1 + "," + var2 + "," ... _ var685 etc.

我对 685 个变量进行了此操作。我知道,我知道,我应该使用 stringbuilder 或 concat 或 join 等。但我认为这将是进行连接的最快方法,并且它是自动生成的。

如果我将它分成两个字符串(例如 longString1 和 longString2),然后将它们加在一起,那么错误就会消失。所以我只是将其替换为:

 string longString1 = var1 + "," + var2 + "," ... _ var400;
 string longString2 = var401 + "," + var402 + "," ... _ var685
 string longString = longString1 + longString2;

错误就消失了。希望这有帮助。

© www.soinside.com 2019 - 2024. All rights reserved.