How to remove warning AD0001 in .Net Core project?
Asked Answered
S

3

5

This is the warning message

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

enter image description here

Any kind of help is appreciated. Thank you

Silveira answered 15/6, 2021 at 1:26 Comment(1)
This GitHub comment could help you: github.com/dotnet/aspnetcore/issues/…Hanaper
A
6

As per: https://github.com/dotnet/aspnetcore/issues/41794

Adding this to a PropertyGroup in the .csproj file fixed this for me in minimal API .net 6.0.

    <NoWarn>AD0001</NoWarn>

The cause in my case is the way the route mapping is done.

// I use this because it's cleaner and the GetAllTodo function has DI parameters
app.MapGet("/manage/todos", GetAllTodo);

// but the following does not raise AD0001
app.MapGet("/manage/todos", () => GetAllTodo());
Ammamaria answered 9/2, 2023 at 20:27 Comment(1)
This should be the answer. Just happened to me as we upgraded to dotnet 8. Adding the () => fixed the issueUnicuspid
U
3

Check this https://github.com/dotnet/aspnetcore/issues/14723

Disable analyzer in Project file for testing purpose only.

<PropertyGroup> <DisableImplicitAspNetCoreAnalyzers>true</DisableImplicitAspNetCoreAnalyzers>
</PropertyGroup>

After disabling this, check if you can still build the project.Check if any install package have prior version dependency.

Uribe answered 15/6, 2021 at 1:49 Comment(0)
S
3

I have been accessing

Microsoft.AspNetCore.MVC

package to access HttpContextAccessor and that causes the WARNING.

I solved this by reinstalling dependency/reference for HttpContextAccesstor and it lands me to this package

Microsoft.AspNetCore.Http.Abstractions

SOLVED

Silveira answered 15/6, 2021 at 2:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.