The API analyzers don't seem to be working in .NET Core 3.0 Preview 8, instead there are error messages in the build output and in the error list, presumably for each instance in the code where the analyzer ran.
CSC : warning AD0001: Analyzer 'Microsoft.AspNetCore.Mvc.Api.Analyzers.ApiConventionAnalyzer' threw an exception of type 'System.NullReferenceException' with message 'Object reference not set to an instance of an object.'.
Using 3.0.100-preview8-013656 and Visual Studio 2019 16.3.0 Preview 2.0
Microsoft.AspNetCore.Mvc.Api.Analyzers from nuget (doesn't matter if latest (2.2.6) or prerelease (3.0.0-preview3-19153-02).The analyzers should either not output anything or output the intended warning.
The full stack trace of the exception from the error list: System.NullReferenceException: Object reference not set to an instance of an object. '.
````
Warning AD0001 Analyzer 'Microsoft.AspNetCore.Mvc.Api.Analyzers.ApiConventionAnalyzer' threw an exception of type 'System.NullReferenceException' with message 'Object reference not set to an instance of an object.'. WebApplication6 1 Active Analyzer 'Microsoft.AspNetCore.Mvc.Api.Analyzers.ApiConventionAnalyzer' threw the following exception:
'Exception occurred with following context:
Compilation: WebApplication6
SyntaxTree: [...]\WebApplication6\WebApplication6\Controllers\WeatherForecastController.cs
SyntaxNode: [HttpGet] public IEnumerable
at Microsoft.CodeAnalysis.CodeAnalysisExtensions.IsAssignableFrom(ITypeSymbol source, ITypeSymbol target)
at Microsoft.CodeAnalysis.CodeAnalysisExtensions.
at Microsoft.CodeAnalysis.CodeAnalysisExtensions.
at System.Linq.Enumerable.AnyTSource at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLockTArg
````
ZIP-File containing project folder after doing File -> New Project and installing the analyzers:
WebApplication6.zip
@wagich in 3.0, the way to reference the API analyzers is by setting a property in your project. I'm working on updating the doc article to clarify this. Here's what you do:
To enable the analyzer in your projects, edit your project file to add the IncludeOpenAPIAnalyzers property:
<PropertyGroup>
<IncludeOpenAPIAnalyzers>true</IncludeOpenAPIAnalyzers>
</PropertyGroup>
I don't see a null ref once I update the project file to remove the analyzer package reference and use the one from the SDK instead.
Thanks for contacting us. We believe that the question you've raised have been answered. If you still feel a need to continue the discussion, feel free to reopen it and add your comments.
@pranavkm thank you very much for the solution, the analyzers started reporting correctly once I removed the nuget package and modified the project.
Unfortunately, in my real project the quick fix(es) don't seem to be working (it works in the sample project). I will investigate further…
Thanks. Feel free to reopen if you have another application that reproduces the issue.