Visual Studio 2015 分析器抛出异常

Visual Studio 2015 Analyzer threw an exception

VS 2015 Update 1 RC 更新到 VS 2015 Update 1 后,我不断收到以下错误消息:

Analyzer 'Microsoft.CodeAnalysis.VisualBasic.CodeFixes.SimplifyTypeNames.VisualBasicSimplifyTypeNamesDiagnosticAnalyzer' threw an exception of type 'System.ArgumentNullException' with message 'Value cannot be null. Parameter name: source'

在我的一个项目上。 代码分析 在该项目上被禁用(因为它在我的解决方案中的所有项目上都是如此),所以我尝试打开和关闭它,但仍然是同样的问题。

似乎我仍然可以构建和 运行 我的解决方案,但升级后事情似乎并没有真正正常工作:

在最近的更新之后或者之前是否有其他人遇到过这个问题?

在这里找到了潜在的解决方法:https://github.com/dotnet/roslyn/issues/6682 由用户 dpoeschl.

发布

这是他的原文:

Workaround: Check this checkbox: Tools | Options | Text Editor | Basic | Code Style | Qualify member access with 'Me'

This workaround has two side-effects (that I can think of so far):

1. You will no longer get a visual indicator of the superfluous Me. or the associated code-fix, or the "Fix all occurrences in" options for easily achieving compliance.

2. Any code generation features that generate fully qualified member accesses and depend on the Simplifier to remove them if appropriate (or that explicitly check this option) will now generate non-compliant code by default.

Enabling this option is particularly non-invasive in both VS2015 & VS2015 Update 1 because this option is only enforced in one direction. That is, the checkbox being unchecked means the analyzer runs, does some deeper analysis (that fails in this case), and offers you a lightbulb when you have qualified member accesses, while the checkbox being checked means that we opt out of the deeper analysis very early and you don't get any lightbulbs telling you to add Me. qualification.

它对我有用,它也可以解决其他人的问题。

更新:

显然,一般问题是代码助手在使用 class 名称时标记对共享 class 类型的调用。

例如

Private Shared Property Instance as Class1

Public Shared Function DefInstance1() as Class1
  ' This causes the warning
  Return Class1.Instance
End Function

Public Shared Function DefInstance2() as Class1
  ' This is okay
  Return Instance
End Function

例如,我从 System.Timers.Timer 继承时为同步对象分配了一个值:

MyBase.SynchronizingObject = value 

而不是

SynchronizingObject = value 

VS 代码助手将其检测为可以简化的类型名称。

另请注意,每次 VS 启动时都会添加一个新警告。

更新:

看起来另一个罪魁祸首是 Visual Studio 在 Application.Designer.vb 中生成的代码:

这个

Global.Microsoft.VisualBasic.ApplicationServices

被标记为简化为

ApplicationServices

似乎 Code Assistant 在 QA 没有注意到手头的问题的情况下变得有点过于激进了。

这是更新 1 中引入的缺陷,自 2015 年 10 月 11 日起已被跟踪 at Roslyn GitHub as #6682
在那里查看状态更新。

更新: Visual Studio 2015 Update 2 is now out 问题已解决。

2016 年 3 月 30 日,Microsoft 发布了 Visual Studio 的新更新。

安装 Visual Studio Update 2 后,问题似乎消失了。这是 VS Update 2 and VS Update 2 Release Notes

查看发行说明,这是他们唯一涉及分析器的内容:

We made Analyzer API improvements, including enabling Analyzer writers to mark their analyzers for concurrent execution, and providing control over whether analyzers run in generated code.