Skip to content

Improve the analyzer load failure diagnostics: CS8032, CS8033 and CS8034 #2683

@mavasani

Description

@mavasani

Currently, the diagnostics generated for analyzer load or instantiation issues are too generic and not to helpful to diagnose the root cause of failure. We have 3 of them (and corresponding VB counterparts), all of which can be enhanced:

  1. CS8032, i.e. WRN_AnalyzerCannotBeCreated = 8032 (http://source.roslyn.io/#Microsoft.CodeAnalysis.CSharp/Errors/ErrorCode.cs,1269) invariably has the below message:
Severity    Code    Description Project File    Line
Warning CS8032  An instance of analyzer Analyzer5.Analyzer5Analyzer cannot be created from C:\Users\mavasani\Documents\Visual Studio 2015\Projects\Analyzer5\Analyzer5\Analyzer5\bin\Debug\Analyzer5.dll: Exception has been thrown by the target of an invocation..    ClassLibrary1       1

We should consider embedding the exception stack trace in the diagnostic's description (on same lines as analyzer exception diagnostics here: http://source.roslyn.io/Microsoft.CodeAnalysis/R/f9e46cc7c756e697.html).

  1. CS8033, i.e. WRN_NoAnalyzerInAssembly = 8033 (http://source.roslyn.io/#Microsoft.CodeAnalysis.CSharp/Errors/ErrorCode.cs,1270) has the below message:
    The assembly {0} does not contain any analyzers.

We generate this diagnostic only when an analyzer assembly has types marked with "DiagnosticAnalyzerAttribute" but has no analyzers for a specific language OR there is mismatch between assembly version of Microsoft.CodeAnalysis.dll referenced by the analyzer vs used by the analyszer host (command line build/IDE). We can make this error message more helpful by pointing out the exact reason, as we already have this information at the point we generate this diagnostic: http://source.roslyn.io/#Microsoft.CodeAnalysis/DiagnosticAnalyzer/AnalyzerFileReference.cs,186

  1. CS834, i.e. WRN_UnableToLoadAnalyzer = 8034 (http://source.roslyn.io/#Microsoft.CodeAnalysis.CSharp/Errors/ErrorCode.cs,1271). Even this diagnostic has just the exception message that caused Assembly load to fail for the analyzer reference assembly. We should embed the exception stack trace in the description here: http://source.roslyn.io/#Microsoft.CodeAnalysis/CommandLine/CommonCommandLineArguments.cs,347

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions