Skip to content

How to read diagnostics messages? #46589

Answered by jmarolf
kulamit asked this question in General
Discussion options

You must be logged in to vote

semanticModel.GetDiagnostics() does not cause analyzers to run, it only asks the compiler to compute diagnostics.

Today if you do

ImmutableArray<DiagnosticAnalyzer> analyzers = ... // set of analyzers you want to run
Compilation compilation = await vsWorkspace.CurrentSolution.GetDocument(location.SourceTree).Project.GetCompilationAsync();
CompilationWithAnalyzers compilationWithAnalyzers = compilation.WithAnalyzers(analyzers);
AnalysisResult analysisResult = await compilationWithAnalyzers.GetAnalysisResultAsync()

analysisResult will contain all the analyzer diagnostics from runnint the analyzers over the project.

@kulamit which version of VS are you using? we plan to change where analyzer…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by jmarolf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants