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

标签 c# visual-studio sonarqube code-analysis

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

我使用 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/

相关文章:

c# - 编辑 DisableTaskMgr 值时出现 "Cannot write to the registry key"错误

c# - ADO.NET 空数据库输出 (mysql)

c# - 如何获得数据表中的特定结果?

maven - 何时在构建工具的 Sonarqube 插件上使用 Sonar 扫描仪?

c# - IIS应用程序池回收触发器: Not enough storage is available to complete this operation (Azure App Service)

c#用do替换字符串包含未知部分

javascript - 如何激活 VS2010 的 JavaScript 进程调试管理器?

visual-studio - 我将构建输出框移到了它自己的窗口。我如何将其移回?

java - 处理 Sonar 规则 "Use Index Of Char"的最佳方式

SonarQube 在代码分析中忽略 getter/setter