vb.net Visual Studio 2015 Analyzer 引发异常

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34042055/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 19:36:44  来源:igfitidea点击:

Visual Studio 2015 Analyzer threw an exception

vb.netvisual-studiovisual-studio-2015code-analysis

提问by mrc

After updating from VS 2015 Update 1 RCto VS 2015 Update 1, I keep getting the following error message:

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'

分析器“Microsoft.CodeAnalysis.VisualBasic.CodeFixes.SimplifyTypeNames.VisualBasicSimplifyTypeNamesDiagnosticAnalyzer”引发了“System.ArgumentNullException”类型的异常,消息“值不能为空”。参数名称:来源'

on one of my projects. Code Analysisis disabled on that project (as it is on all of my projects in the solution), so I tried to turn it on and off but still the same issue.

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

It seems that I can still build and run my solution, but things don't really seem to work properly after the upgrade:

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

  • everything is running really slow
  • after making changes and building it doesn't apply the changes
  • 一切都运行得很慢
  • 进行更改并构建后,它不会应用更改

Did anyone else have this issue after the recent update or maybe even before?

有没有其他人在最近的更新之后甚至之前遇到过这个问题?

Potential work-around found in here: https://github.com/dotnet/roslyn/issues/6682posted by user dpoeschl.

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

And this is his original text:

这是他的原文:

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

dpoeschl's solution

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.

解决方法:选中此复选框:工具 | 选项 | 文本编辑器 | 基本 | 代码风格 | 使用“我”获得会员资格

dpoeschl 的解决方案

这种解决方法有两个副作用(我目前能想到的):

1.你将不再获得多余的我的视觉指示。或相关的代码修复,或“修复所有出现的地方”选项以轻松实现合规性。

2.任何生成完全限定成员访问并依赖简化器在适当情况下删除它们(或明确选中此选项)的代码生成功能现在默认生成不兼容的代码。

在 VS2015 和 VS2015 Update 1 中启用此选项特别无创,因为此选项仅在一个方向上强制执行。也就是说,未选中复选框意味着分析器运行,进行一些更深入的分析(在这种情况下失败),并在您具有合格的成员访问权限时为您提供一个灯泡,而选中的复选框意味着我们选择退出更深入的分析很早,你没有得到任何灯泡告诉你添加我。资格。

It has worked for me, it might as well fix the problem for others.

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

采纳答案by miroxlav

This is a defect introduced in Update 1 and it is already tracked at Roslyn GitHub as #6682since 2015-10-11.
Check there for status updates.

这是更新 1 中引入的一个缺陷,自2015 年 10 月 11 日以来,它已在 Roslyn GitHub 上跟踪为 #6682
检查那里的状态更新。

Update:Visual Studio 2015 Update 2 is now outand the problem is fixed there.

更新:Visual Studio 2015 Update 2 现已发布,问题已在那里解决。

回答by David

Update:

更新:

Apparently, the general issue is the code assistant is flagging calls to Shared class types when the class name is used.

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

For example

例如

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

For example, I assigned a value to the Synchronizing Object when inheriting from System.Timers.Timer as:

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

MyBase.SynchronizingObject = value 

Instead of

代替

SynchronizingObject = value 

The VS Code Assistant detected this as a type name that can be simplified.

VS Code 助手将此检测为可以简化的类型名称。

Note also, that a new warning is added each time VS starts.

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

Update:

更新:

It looks like another culprit is in the code generated by Visual Studio in the Application.Designer.vb:

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

this

这个

Global.Microsoft.VisualBasic.ApplicationServices

is tagged for simplification to

被标记为简化为

ApplicationServices

It seems that Code Assistant has become a bit over-aggressive without QA noticing the issues at hand.

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

回答by mrc

On March 30th, 2016, Microsoft released a new update for Visual Studio.

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

After installing Visual Studio Update 2 the issue seems to go away. This is the VS Update 2and VS Update 2 Release Notes

安装 Visual Studio Update 2 后,问题似乎消失了。这是VS Update 2VS Update 2 发行说明

Checking the Release Notes, this is the only thing they have touched with regards to the Analyzer:

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

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.

我们对分析器 API 进行了改进,包括让分析器编写者能够将他们的分析器标记为并发执行,并提供对分析器是否在生成的代码中运行的控制。