AD0001 Analyzer 'Microsoft.AspNetCore.Mvc.Analyzers.TopLevelParameterNameAnalyzer' threw an exception
Steps to Reproduce:
- Build solution after upgrading to dot net core 3.1.101
Expected Behavior: Solution builds without errors
Actual Behavior: CSC : error AD0001: Analyzer 'Microsoft.AspNetCore.Mvc.Analyzers.TopLevelParameterNameAnalyzer' threw an exception of type 'System.NullReferenceException' with message 'Object reference not set to an instance of an object.'.
I feel like this may have something to do with this issue, but I'm unsure why this would be occuring.

happy to close this now based on the following thread seemingly being the cause: https://github.com/dotnet/aspnetcore/issues/14723#issuecomment-588941408
As less dramatic workaround, you can just disable the MVC1004 rule by adding a .editorconfig file, and add a rule disabling it.
Here is the quick workaround:
- Add a new item to the WebAPI project
- In the search box add “editorconfig” and then select the “editorconfig File (.NET)”. Use the “.editorconfig” as name for the file
- Under the
[*.{cs,vb}]section, add the ruledotnet_diagnostic.MVC1004.severity = noneto disable this rule, and save the file - Build the project and voilà, problem solved! I continue getting other code analysis warnings, but not this one.
I tried to add the comment in the original issue #14723 but looks locked now. Also wrote a blog post about this available at https://intelequia.com/blog/post/2125/workaround-ad0001-analyzer-microsoft-aspnetcore-mvc-analyzers-toplevelparameternameanalyzer-threw-an-exception
Thanks @davidjrh . I think disabling the MVC1004 is the best solution for now. Btw the URL is not working that you shared. On the other hand I realised that I'm getting this error if I use a method with parameters like this;
[HttpPost]
[Route("{entityType}")]
public async Task<ActionResult> Receive(string entityType, IFormFile file)
{
...
}