dotnet / roslyn-analyzers

MIT License
1.59k stars 466 forks source link

Analyzer 'System.Runtime.Analyzers.CSharpAvoidZeroLengthArrayAllocationsAnalyzer' threw an exception of type 'System.InvalidCastException' with message 'Specified cast is not valid.'. #850

Closed mavasani closed 8 years ago

mavasani commented 8 years ago
  1. Clean RoslynDev hive on your machine
  2. Get latest sources of roslyn and build
  3. Get latest sources of roslyn-analyzers and build
  4. devenv /rootsuffix RoslynDev
  5. Open Roslyn.sln

Got the following AD0001 in the error list:

Severity    Code    Description Project File    Line    Source  Tool    Detail Description
Error   AD0001  Analyzer 'System.Runtime.Analyzers.CSharpAvoidZeroLengthArrayAllocationsAnalyzer' threw an exception of type 'System.InvalidCastException' with message 'Specified cast is not valid.'. CSharpScriptingTest.Desktop     1   IntelliSense    System.Runtime.CSharp.Analyzers Analyzer 'System.Runtime.Analyzers.CSharpAvoidZeroLengthArrayAllocationsAnalyzer' threw the following exception:
'Exception occurred with following context:
Compilation: Microsoft.CodeAnalysis.CSharp.Scripting.Desktop.UnitTests
IOperation: ArrayCreationExpression
SyntaxTree: C:\roslyn-internal\Open\src\Scripting\CSharpTest.Desktop\ObjectFormatterTests.cs
SyntaxNode: "Hashtable(1)" [LiteralExpressionSyntax]@[1327..1341) (37,31)-(37,45)

System.InvalidCastException: Specified cast is not valid.
   at System.Runtime.Analyzers.AvoidZeroLengthArrayAllocationsAnalyzer.AnalyzeOperation(OperationAnalysisContext context) in C:\roslyn-analyzers\src\System.Runtime.Analyzers\Core\AvoidZeroLengthArrayAllocations.cs:line 75
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.<>c__DisplayClass43_1.<ExecuteOperationAction>b__1()
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock(DiagnosticAnalyzer analyzer, Action analyze, Nullable`1 info)
-----
'.
mavasani commented 8 years ago

This is showing up when trying to move Roslyn.sln to new analyzer packages. Need to re-enable this rule on Roslyn.sln once this issue is fixed and Roslyn moves to newer analyzer packages.