CA0001:对象引用不设置到对象的实例 [英] CA0001: Object reference not set to an instance of an object

查看:645
本文介绍了CA0001:对象引用不设置到对象的实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请先阅读问题,标记它作为复制的对象引用不设置到对象的实例之前

我运行具有SonarQube构建。我收到以下错误:

I run a build with SonarQube. I get the following error:

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的分析发生错误。
我试着将它添加到在SonarQube分析范围源文件排除排除分析文件。如果没有工作,我加了一个排除进入的csproj文件:

The error happens since I turned on NDepend Analysis in SonarQube. I tried excluding the File from Analysis by adding it to the Source File Exclusions in the SonarQube Analysis scope. When that did not work, I added a exclusion into the csproj file:

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



但不幸的是,错误仍然不断弹出。当我运行在Visual Studio代码分析项目,会出现同样的错误。因此,我认为它无关NDepend的。关闭所有的NDepend的规则后,错误仍然无法构建。

But unfortunately, the error still keeps popping up. When I run the Visual Studio Code Analysis for the project, the same error appears. So I think it has nothing to do with NDepend. After turning off all the NDepend rules, the error still fails the build.

NDepend的支持让我到下面的网站

NDepend Support referred me to the following WebSite

的类,它不能分析这样开始:

The class that it cannot analyse starts like this:

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



任何建议如何摆脱这种错误的?

Any suggestions how to get rid of this error?

推荐答案

我没有办法来解决这个错误。但是有一个解决方法。这是微软代码分析的一个已知的问题发生,当一个通用类包含并使用的接口。这个问题可以的 Microsoft连接的。链接的问题包含重现该问题的附件。

I don't have a way to fix this error. But there is a workaround. It is a known issue of the Microsoft Code Analysis that occurs, when a generic class contains and uses an interface. The issue can be found on Microsoft Connect. The linked issue contains an Attachment which reproduces the problem.

解决方法是提取接口,并把它定义泛型类之外。

The workaround is to extract the interface and define it outside of the generic class.

这篇关于CA0001:对象引用不设置到对象的实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆