Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio 2015 Analyzer threw an exception

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

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

on one of my projects. Code Analysis is 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/6682 posted by user 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.

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

like image 927
mrc Avatar asked Dec 02 '15 11:12

mrc


2 Answers

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

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

like image 189
miroxlav Avatar answered Nov 02 '22 04:11

miroxlav


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:

MyBase.SynchronizingObject = value 

Instead of

SynchronizingObject = value 

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

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

Update:

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

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.

like image 40
David Avatar answered Nov 02 '22 04:11

David