如何在 .Net Core 项目中移除警告 AD0001?

4

这是一个警告信息

警告 AD0001: 分析器 'Microsoft.AspNetCore.Mvc.Analyzers.TopLevelParameterNameAnalyzer' 抛出了一个 'System.NullReferenceException' 类型的异常,消息为“对象引用未设置为对象的实例。”。

enter image description here

希望能得到任何形式的帮助。谢谢


这个 GitHub 评论可能会对你有所帮助:https://github.com/dotnet/aspnetcore/issues/14723#issuecomment-588389938 - Yong Shun
3个回答

3

请查看https://github.com/dotnet/aspnetcore/issues/14723

仅用于测试目的,在项目文件中禁用分析器。

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

禁用后,请检查是否仍然可以构建项目。检查是否存在先前版本依赖的任何安装包。


3

我一直在使用Microsoft.AspNetCore.MVC包来访问HttpContextAccessor,这导致了警告。

我通过重新安装HttpContextAccesstor的依赖/引用来解决这个问题,并且它将我带到了这个包中:

Microsoft.AspNetCore.Http.Abstractions

问题已解决。


2
根据: https://github.com/dotnet/aspnetcore/issues/41794 在.csproj文件的PropertyGroup中添加此内容可以解决我在最小API .net 6.0中遇到的问题。
    <NoWarn>AD0001</NoWarn>

在我的情况下,原因是路由映射的方式。

// 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());

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接