roslyn icon indicating copy to clipboard operation
roslyn copied to clipboard

AD0001 Analyzer 'Microsoft.AspNetCore.Mvc.Analyzers.TopLevelParameterNameAnalyzer' threw an exception

Open OwenPattison opened this issue 6 years ago • 4 comments

Steps to Reproduce:

  1. 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.'.

OwenPattison avatar Feb 19 '20 15:02 OwenPattison

I feel like this may have something to do with this issue, but I'm unsure why this would be occuring.

image

OwenPattison avatar Feb 19 '20 16:02 OwenPattison

happy to close this now based on the following thread seemingly being the cause: https://github.com/dotnet/aspnetcore/issues/14723#issuecomment-588941408

OwenPattison avatar Feb 20 '20 13:02 OwenPattison

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:

  1. Add a new item to the WebAPI project
  2. In the search box add “editorconfig” and then select the “editorconfig File (.NET)”. Use the “.editorconfig” as name for the file
  3. Under the [*.{cs,vb}] section, add the rule dotnet_diagnostic.MVC1004.severity = none to disable this rule, and save the file
  4. 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

davidjrh avatar May 12 '21 18:05 davidjrh

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)
{
    ...
}

onka13 avatar Feb 03 '22 11:02 onka13