Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intermittent NullReferenceException in CSharpDiagnosticAnalyzerApiUsageAnalyzer #1771

Closed
jinujoseph opened this issue Aug 8, 2018 · 11 comments
Assignees
Labels
Area-Microsoft.CodeAnalysis.Analyzers Bug The product is not behaving according to its current intended design Resolution-Fixed

Comments

@jinujoseph
Copy link
Contributor

From @yaakov-h on August 7, 2018 3:58

Version Used:
Microsoft.CodeAnalysis.Analyzers v2.6.1

Steps to Reproduce:

  1. Clone https://github.com/WiseTechGlobal/WTG.Analyzers at commit 223095d2
  2. Build from source

Expected Behavior:

No null reference exceptions in MS analyzers

Actual Behavior:

Sometimes null reference exception in MS analyzers

CSC : error AD0001: Analyzer 'Microsoft.CodeAnalysis.CSharp.Analyzers.MetaAnalyzers.CSharpDiagnosticAnalyzerApiUsageAnalyzer' threw an exception of type 'System.NullReferenceException' with message 'Object reference not set to an instance of an object.'. [C:\projects\wtg-analyzers\WTG.Analyzers.Test\WTG.Analyzers.Test.csproj]

Copied from original issue: dotnet/roslyn#29119

@jinujoseph
Copy link
Contributor Author

From @sharwell on August 7, 2018 16:24

@jinujoseph Can you move this to dotnet/roslyn-analyzers

@mavasani
Copy link
Contributor

mavasani commented Aug 8, 2018

@yaakov-h I am unable to build your solution:

1>------ Build started: Project: WTG.Analyzers.Utils, Configuration: Debug Any CPU ------
1>c:\WTG.Analyzers\WTG.Analyzers.Utils\WTG.Analyzers.Utils.csproj(11,3): error MSB4019: The imported project "c:\WTG.Analyzers\.paket\Paket.Restore.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.
1>Done building project "WTG.Analyzers.Utils.csproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

@mavasani
Copy link
Contributor

mavasani commented Aug 8, 2018

mavasani added a commit to mavasani/roslyn-analyzers that referenced this issue Aug 8, 2018
@mavasani mavasani self-assigned this Aug 8, 2018
@mavasani mavasani added Bug The product is not behaving according to its current intended design Area-Microsoft.CodeAnalysis.Analyzers 4 - In Review labels Aug 8, 2018
@mavasani mavasani added this to the 15.8 milestone Aug 8, 2018
@camainc
Copy link

camainc commented Jan 15, 2019

I'm using the latest bits and I still get this warning. I don't want to see any warnings at all. How do I get rid of these?

@niklaskihl
Copy link

Here's how you can solve this for the time being: agracio/edge-js#61

@mavasani
Copy link
Contributor

mavasani commented Jan 16, 2019

@camainc @niklaskihl Do you have a repro that I can use to investigate?

Meanwhile, you can workaround by adding a /nowarn:RS1022 or a ruleset entry: <Rule Id="RS1022" Action="None" />, you don't need to downgrade the analyzer package or Microsoft.CodeAnalysis package version.

<?xml version="1.0" encoding="utf-8"?>
<RuleSet Name="New Rule Set" Description=" " ToolsVersion="15.0">
  <Rules AnalyzerId="Microsoft.CodeAnalysis.Analyzers" RuleNamespace="Microsoft.CodeAnalysis.Analyzers">
    <Rule Id="RS1022" Action="None" />
  </Rules>
</RuleSet>

@mavasani
Copy link
Contributor

@camainc @niklaskihl Can you see if this comment matches your repro: #1888 (comment)? If so, can you try to add an explicit package reference to Microsoft.CodeAnalysis.Analyzers version 2.6.3 in your failing project?

@alphaleonis
Copy link

@camainc @niklaskihl Can you see if this comment matches your repro: #1888 (comment)? If so, can you try to add an explicit package reference to Microsoft.CodeAnalysis.Analyzers version 2.6.3 in your failing project?

@mavasani This seems to have solved it for us anyway! Thanks!

@IngvarKofoed
Copy link

I'm writing my own analyzer and ran into this exception in the project were I used the analyzer. After some time I finally found out that the way I references Microsoft.CodeAnalysis.Analyzers in the analyzer code is very important. The PrivateAssets="all" is important. If this is not there, then I get the NullReferenceException in the project using the analyzer.

From my analyzer csproj:
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="2.6.1" PrivateAssets="all" /> <PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="2.9.0" PrivateAssets="all" />

This comment might be misplaced, but I fixed "the issue" for me :)

@PeterPann23
Copy link

I looked at the whole thread, I am using VS 2019 Preview, latest patch and I have always had this error on my .Net Core 3.0 projects.

Severity Code Description Project File Line Suppression State Warning AD0001 Analyzer 'Microsoft.CodeAnalysis.CSharp.Diagnostics.RemoveUnnecessaryCast.CSharpRemoveUnnecessaryCastDiagnosticAnalyzer' threw an exception of type 'System.NullReferenceException' with message 'Object reference not set to an instance of an object.'. Cats.DeepBook 1 Active

None of the above fixes works for me, I also do not reference Microsoft.CodeAnalysis.Analyzers.

@mavasani
Copy link
Contributor

@PeterPann23 - The analyzer in your repro (CSharpRemoveUnnecessaryCastDiagnosticAnalyzer) is different from the analyzer in this issue (CSharpDiagnosticAnalyzerApiUsageAnalyzer )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Microsoft.CodeAnalysis.Analyzers Bug The product is not behaving according to its current intended design Resolution-Fixed
Projects
None yet
Development

No branches or pull requests

7 participants