gpt4 book ai didi

c# - CA0001 : Object reference not set to an instance of an object

转载 作者:行者123 更新时间:2023-11-30 17:39:24 25 4
gpt4 key购买 nike

请先阅读问题,然后再将其标记为重复“对象引用未设置为对象的实例”

我使用 SonarQube 运行构建。我收到以下错误:

CA0001 : Rule=Microsoft.Design#CA1011, Target=Company.Project.Service.Report.Wrappers.Helper.ReportPrintingOrderDriver`2.#DrivePrintingProcess(Company.Product.Service.Contracts.Report.CommonExportReportRequest,Company.Project.Common.Containers.LIHierarchy`3<!0,!1,System.Int32>,Company.Project.Service.Report.Wrappers.Helper.ReportPrintingOrderDriver`2<!0,!1>+IReportPrintingOrderDriven) : Object reference not set to an instance of an object.

错误发生是因为我在 SonarQube 中打开了 NDepend Analysis。我尝试通过将文件添加到 SonarQube 分析范围中的源文件排除来从分析中排除该文件。当这不起作用时,我在 csproj 文件中添加了一个排除项:

<Compile Include="Wrappers\Helper\ReportPrintingOrderDriver.cs" >
<!-- Exclude the file from analysis -->
<SonarQubeExclude>true</SonarQubeExclude>
</Compile>

但不幸的是,错误仍然不断出现。当我为项目运行 Visual Studio Code Analysis 时,出现了同样的错误。所以我认为这与 NDepend 无关。关闭所有NDepend规则后,错误依旧是构建失败。

NDepend 支持让我引用以下 WebSite

它无法分析的类是这样开始的:

public class ReportPrintingOrderDriver<TInnerNode, TDataNode> where TDataNode : IComparable<TDataNode>, IMergeable<TDataNode>
{
...
}

有什么建议可以消除这个错误吗?

最佳答案

我没有办法修复这个错误。但是有一个解决方法。当泛型类包含并使用接口(interface)时,会发生 Microsoft 代码分析的一个已知问题。可以在 Microsoft Connect 上找到该问题.链接的问题包含重现问题的附件。

解决方法是提取接口(interface)并在泛型类之外定义它。

关于c# - CA0001 : Object reference not set to an instance of an object,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35576418/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com