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

Remaining NRE in CSharpDiagnosticAnalyzerApiUsageAnalyzer #1888

Closed
frblondin opened this issue Nov 14, 2018 · 18 comments
Closed

Remaining NRE in CSharpDiagnosticAnalyzerApiUsageAnalyzer #1888

frblondin opened this issue Nov 14, 2018 · 18 comments

Comments

@frblondin
Copy link

Analyzer package

Microsoft.CodeAnalysis.CSharp.Analyzers

Package Version

v2.6.2

Diagnostic ID

None provided.

Repro steps

  1. Clone this repo and switch to branch feature/metaprogramming
  2. Compile solution -> first validation fails with error below for project GitObjectDb
  3. New compilation -> works for GitObjectDb, fails for next project

Interesting thing to note, CodeGeneration.Roslyn is used by failing projects.

Actual behavior

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.'.

I'd like to know how to debug such errors so I can submit a PR.

@frblondin
Copy link
Author

Workaround was ignoring rule RS1022.

@paul1956
Copy link

paul1956 commented Dec 7, 2018

@frblondin I am still seeing this error in VS 2017.15.9.3 how can I get the fix.

@mavasani
Copy link
Contributor

mavasani commented Dec 7, 2018

@paul1956 Can you try the latest 2.6.XXX NuGet package from https://dotnet.myget.org/feed/roslyn-analyzers/package/nuget/Microsoft.CodeAnalysis.FxCopAnalyzers/2.6.3-beta1.18566.1+3a9597c6 ? Hoping to publish it to nuget soon...

@paul1956
Copy link

paul1956 commented Dec 8, 2018

Same error, is there any information I can provide to help? I published the failing project https://github.com/paul1956/CSharpToVB

@frblondin
Copy link
Author

@paul1956 the workaround is to ignore the RS1022 rule in the Rule.ruleset file:

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

Go here if you need guidance on how to use & appy ruleset files.

@mavasani
Copy link
Contributor

mavasani commented Dec 9, 2018

Paul, do you have a stand-alone repro that I can use?

@mavasani
Copy link
Contributor

mavasani commented Dec 9, 2018

I see you provided a repro, I will investigate.

@mavasani
Copy link
Contributor

@paul1956 - Unable to repro the error with the project you provided. The project does not even build for me, not sure if I need additional steps:

Severity	Code	Description	Project	File	Line	Suppression State
Error		Unable to find manifest signing certificate in the certificate store.	CSharpToVB			
Error	BC30451	'Split' is not declared. It may be inaccessible due to its protection level.	CodeConverter	C:\CSharpToVB\CodeConverter\Utils\StatementMarkerSupport.vb	101	Active
Error	BC30451	'Space' is not declared. It may be inaccessible due to its protection level.	CodeConverter	C:\CSharpToVB\CodeConverter\Utils\SyntaxNormalizer.vb	634	Active
Error	BC30518	Overload resolution failed because no accessible 'TryGetDelimiterLengthAndType' can be called with these arguments:	CodeConverter	C:\CSharpToVB\CodeConverter\Utils\UnicodeNewline.vb	366	Active
Error	BC30518	Overload resolution failed because no accessible 'TryGetDelimiterLengthAndType' can be called with these arguments:	CodeConverter	C:\CSharpToVB\CodeConverter\Utils\UnicodeNewline.vb	400	Active
Error	BC2017	could not find library 'C:\CSharpToVB\CSharpToVB\bin\Debug\CSharpToVBApp.exe'	CSharpToVB.Tests	C:\CSharpToVB\CSharpToVB.Tests\vbc	1	Active
Error	BC2017	could not find library 'C:\CSharpToVB\CodeConverter\bin\Debug\netstandard2.0\VB.CodeConverter.dll'	CSharpToVB.Tests	C:\CSharpToVB\CSharpToVB.Tests\vbc	1	Active
Error	BC30451	'Space' is not declared. It may be inaccessible due to its protection level.	CodeConverter	C:\CSharpToVB\CodeConverter\CSharpToVB\MethodBodyVisitor.vb	457	Active

@mavasani
Copy link
Contributor

@frblondin I am unable to find your feature branch and building the master branch seems to be fail. Again, do I need some additional setup steps? Can you point me to the documentation about setting up your project for build?

@frblondin
Copy link
Author

@mavasani thanks for looking at this.
Here is the repro scenario:

  1. Clone https://github.com/frblondin/GitObjectDb.git
  2. Edit Rules.ruleset and remove <Rule Id="RS1022" Action="None" />
  3. Open Visual Studio and compile -> 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.'.

This error shows up only once, later builds work. You need to change code... or close Visual Studio, execute git clean -xdf . and repeat step 3.

The master branch should be compiling: tested on various computers, compiles on AppVeyor... please share the errors you are getting if any.

@frblondin frblondin reopened this Jan 16, 2019
@mavasani
Copy link
Contributor

@frblondin Thanks, I was able to repro the AD0001/NRE. However, I noticed that the AD0001 is firing in your test project which is still referencing version 2.6.1 of Microsoft.CodeAnalysis.Analyzers NuGet package, which had this known bug. Note that Microsoft.CodeAnalysis.FxCopAnalyzers does not include Microsoft.CodeAnalysis.Analyzers as a dependency. v2.6.1 of Microsoft.CodeAnalysis.Analyzers is likely coming in your test project as a transitive asset from some other NuGet package. As soon as I add an explicit NuGet package reference to v2.6.3 of Microsoft.CodeAnalysis.Analyzers in your test project, the AD0001 is no longer seen:

    <PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="2.6.3">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
    </PackageReference>

Also tagging @jmarolf - probably we should move the Microsoft.CodeAnalysis.Analyzers referenced by Microsoft.CodeAnalysis NuGet package forward from 2.6.1 to 2.6.3. Can you remind me where should I make this change - roslyn-sdk repo or roslyn repo?

@mavasani
Copy link
Contributor

@paul1956 Can you also confirm this for your repro? Does adding an explicit package reference to "Microsoft.CodeAnalysis.Analyzers" Version="2.6.3" fix your AD0001?

@paul1956
Copy link

The repo is continuedly being updates, there is a stable version now but it does not show the error. I should have provided the version that had the error. I now have an explicit reference to Microsoft.CodeAnalysis.Analyzers" Version="2.6.3" and have not seen the error.

@frblondin
Copy link
Author

Confirm that it works now. I don't know if you want to keep this issue open until @jmarolf gets back to you... otherwise feel free to close it.
Thanks @mavasani

@jmarolf
Copy link
Contributor

jmarolf commented Jan 17, 2019

@mavasani https://github.com/dotnet/roslyn-sdk is the correct place to make these changes

Example: C# Console App

@mavasani
Copy link
Contributor

@jmarolf - I meant we need to update the nuspec for Microsoft.CodeAnalysis so the NuGet package itself has a package dependency on v2.6.3 of Microsoft.CodeAnalysis.Analayzers, currently it references 2.6.1

@mavasani
Copy link
Contributor

Filed dotnet/roslyn-sdk#243 to ensure we update the nuspec for Microsoft.CodeAnalysis.

@jmarolf
Copy link
Contributor

jmarolf commented Jan 18, 2019

The nuget package definition for Microsoft.Codeanalysis lives in dotnet/rosyln

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants