You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp2
{
class Program
{
static void Main(string[] args)
{
}
public void Method(IEnumerable<string> items)
{
foreach (var item in items)
{
switch (item)
{
case "a":
{
break;
}
default:
throw new ArgumentOutOfRangeException(nameof(item), item, null);
}
}
}
}
}
When compiling the following simple console application, SonarAnalyzer.CSharp gives the exception:
AD0001 Analyzer 'SonarAnalyzer.Rules.CSharp.CheckArgumentException' threw an exception of type 'System.NullReferenceException' with message 'Object reference not set to an instance of an object.'. ConsoleApp2 1 Active Analyzer 'SonarAnalyzer.Rules.CSharp.CheckArgumentException' threw the following exception:
'Exception occurred with following context:
Compilation: ConsoleApp2
SyntaxTree: C:\Users\anton.ryzhov\Documents\Visual Studio 2017\Projects\ConsoleApp2\ConsoleApp2\Program.cs
SyntaxNode: new ArgumentOutOfRangeException ... [ObjectCreationExpressionSyntax]@[384..441) (18,22)-(18,79)
System.NullReferenceException: Object reference not set to an instance of an object.
at SonarAnalyzer.Rules.CSharp.CheckArgumentException.TakeOnlyBeforeDot(Optional`1 value)
at SonarAnalyzer.Rules.CSharp.CheckArgumentException.CheckForIssue(SyntaxNodeAnalysisContext analysisContext)
at SonarAnalyzer.Helpers.DiagnosticAnalyzerContextHelper.<>c__DisplayClass0_0`1.<RegisterSyntaxNodeActionInNonGenerated>b__0(SyntaxNodeAnalysisContext c)
at SonarAnalyzer.Helpers.SonarAnalysisContext.<>c__DisplayClass12_0`1.<RegisterSyntaxNodeAction>b__0(SyntaxNodeAnalysisContext c)
at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.<>c__43`1.<ExecuteSyntaxNodeAction>b__43_0(ValueTuple`2 data)
at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock[TArg](DiagnosticAnalyzer analyzer, Action`1 analyze, TArg argument, Nullable`1 info)
When compiling the following simple console application, SonarAnalyzer.CSharp gives the exception:
EDIT: I have changed the styling (@Evangelink)
The text was updated successfully, but these errors were encountered: