简体   繁体   中英

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

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM