CA0001: Object reference not set to an instance of an object

丶灬走出姿态 提交于 2019-12-23 21:48:13

问题


Please read the question first, before flagging it as duplicate for "Object reference not set to an instance of an object"

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.

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>

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 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?


回答1:


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.



来源:https://stackoverflow.com/questions/35576418/ca0001-object-reference-not-set-to-an-instance-of-an-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!