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

SA1135 throws null reference exception when using dotnet core 3.1.2 #3136

Closed
and-rewsmith opened this issue Mar 23, 2020 · 4 comments · Fixed by #3180
Closed

SA1135 throws null reference exception when using dotnet core 3.1.2 #3136

and-rewsmith opened this issue Mar 23, 2020 · 4 comments · Fixed by #3180
Assignees

Comments

@and-rewsmith
Copy link

and-rewsmith commented Mar 23, 2020

I am currently updating the iotedge repo to from dotnet core 2.1.13 to 3.1.2.

I ran into the following error when executing dotnet build -c release, which uses stylecop.

Microsoft (R) Build Engine version 16.5.0+d4cbfca49 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Restore completed in 358.8 ms for /home/als5ev/Desktop/iotedge/edge-util/src/Microsoft.Azure.Devices.Edge.Util/Microsoft.Azure.Devices.Edge.Util.csproj.
  Restore completed in 358.8 ms for /home/als5ev/Desktop/iotedge/edge-util/src/Microsoft.Azure.Devices.Edge.Storage/Microsoft.Azure.Devices.Edge.Storage.csproj.
  Restore completed in 358.79 ms for /home/als5ev/Desktop/iotedge/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Core/Microsoft.Azure.Devices.Edge.Agent.Core.csproj.
  Microsoft.Azure.Devices.Edge.Util -> /home/als5ev/Desktop/iotedge/edge-util/src/Microsoft.Azure.Devices.Edge.Util/bin/release/netcoreapp3.1/Microsoft.Azure.Devices.Edge.Util.dll
  Microsoft.Azure.Devices.Edge.Storage -> /home/als5ev/Desktop/iotedge/edge-util/src/Microsoft.Azure.Devices.Edge.Storage/bin/release/netcoreapp3.1/Microsoft.Azure.Devices.Edge.Storage.dll
CSC : error AD0001: Analyzer 'StyleCop.Analyzers.ReadabilityRules.SA1135UsingDirectivesMustBeQualified' threw an exception of type 'System.NullReferenceException' with message 'Object reference not set to an instance of an object.'. [/home/als5ev/Desktop/iotedge/edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Core/Microsoft.Azure.Devices.Edge.Agent.Core.csproj]

I also tested on dotnet core 3.1.102 and this does not occur.

kodiakhq bot pushed a commit to Azure/iotedge that referenced this issue Apr 7, 2020
Fix build due to SA1135 when build with .Net Core 3.1. Will re-enable it once DotNetAnalyzers/StyleCopAnalyzers#3136 is resolved.
@dymanoid
Copy link
Contributor

This issue is caused by the Roslyn compiler change introduced with dotnet/roslyn#41828.

Since then, INamedTypeSymbol.TupleUnderlyingType returns null for value tuples without named fields. So, this line sets symbol to null:

And then this line throws:

Interestingly enough, there are a couple of unit tests that should cover this use case:

  • TestFullyQualifiedAliasInsideNamespaceAsync
  • TestFullyQualifiedAliasAsync
  • etc.

However, they seem to not cover the expected case. Despite the passing results, the tests don't actually run the code causing the NRE.

The reason is: INamedTypeSymbol.IsTupleType returns false for the type-in-test System.ValueTuple<System.Collections.IList, int>.

(The concrete symbol descriptor object is Microsoft.CodeAnalysis.CSharp.Symbols.ConstructedNamedTypeSymbol from Microsoft.CodeAnalysis.CSharp, Version=1.3.1.0.)

I tried to use

typeSymbol.TupleUnderlyingType() ?? typeSymbol

(like it's being used in Roslyn now, see e.g. this), but that didn't really work because TupleTypeSyntaxWrapper.IsInstance always returns false then and we get a StackOverflowException in SymbolNameHelpers.AppendQualifiedSymbolName.

@sharwell Could you maybe outline a solution for this or give me an idea? I'd be glad to help by providing a PR. I'm confused by the fact that INamedTypeSymbol.IsTupleType is false in the unit tests. Do we have a problem with Microsoft.CodeAnalysis.CSharp?

@vweijsters vweijsters self-assigned this Jul 26, 2020
@vweijsters
Copy link
Contributor

I have failing unit tests after updating the Microsoft.CodeAnalysis package in the StyleCop.Analyzers.Test.CSharp8 project to version 3.6.0. I'll have a look on how to fix this.

@matan-yadgar
Copy link

matan-yadgar commented Nov 5, 2024

im still getting this. using .NET 8 (c#).

error: CSC : error AD0001: Analyzer 'StyleCop.Analyzers.LayoutRules.SA1500BracesForMultiLineStatementsMustNotShareLine' threw an exception of type 'System.NullReferenceException' with message 'Object reference not set to an instance of an object.'. (some path to my csproj file)

inclusion in project:

all
runtime; build; native; contentfiles; analyzers; buildtransitive

tried to ignore it in the ".editconfig" file:

broken code comented out

dotnet_diagnostic.AD0001.severity = None

not using a "stylecop.json" file.

running the command:

"dotnet build MySolution.sln --no-restore --configuration Release /p:RunAnalyzersDuringBuild=true -warnaserror"

any ideas?

@bjornhellander
Copy link
Contributor

@matan-yadgar This issue was about SA1135 throwing exceptions and in your case it's SA1500, so it's not the same problem. If you are not using the latest beta (1.2.0-beta.556), please try that one. Otherwise create a new issue and someone can try to help you.

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

Successfully merging a pull request may close this issue.

6 participants