@@ -55,7 +55,25 @@ public override void Initialize(AnalysisContext context)
5555 /// <returns>A parameter list for the delegate parameters.</returns>
5656 internal static ParameterListSyntax GetDelegateParameterList ( IMethodSymbol methodSymbol , int argumentIndex )
5757 {
58- var delegateType = ( INamedTypeSymbol ) methodSymbol . Parameters [ argumentIndex ] . Type ;
58+ var realIndex = Math . Min ( argumentIndex , methodSymbol . Parameters . Length - 1 ) ;
59+
60+ var type = methodSymbol . Parameters [ realIndex ] . Type ;
61+
62+ if ( methodSymbol . Parameters [ realIndex ] . IsParams )
63+ {
64+ if ( type is IArrayTypeSymbol arrayTypeSymbol )
65+ {
66+ type = arrayTypeSymbol . ElementType ;
67+ }
68+ else
69+ {
70+ // Just to make sure that we do not crash if in future versions of the compiler other types are allowed for params.
71+ // This if statement should be extended if e.g. Span params are introduced into the language.
72+ return null ;
73+ }
74+ }
75+
76+ var delegateType = ( INamedTypeSymbol ) type ;
5977 var delegateParameters = delegateType . DelegateInvokeMethod . Parameters ;
6078
6179 var syntaxParameters = GetSyntaxParametersFromSymbolParameters ( delegateParameters ) ;
@@ -95,8 +113,7 @@ private static bool HandleMethodInvocation(SemanticModel semanticModel, Anonymou
95113 // invocation -> argument list -> argument -> anonymous method
96114 var argumentListSyntax = argumentSyntax ? . Parent as ArgumentListSyntax ;
97115
98- var originalInvocationExpression = argumentListSyntax ? . Parent as InvocationExpressionSyntax ;
99- if ( originalInvocationExpression != null )
116+ if ( argumentListSyntax ? . Parent is InvocationExpressionSyntax originalInvocationExpression )
100117 {
101118 SymbolInfo originalSymbolInfo = semanticModel . GetSymbolInfo ( originalInvocationExpression ) ;
102119
@@ -113,6 +130,12 @@ private static bool HandleMethodInvocation(SemanticModel semanticModel, Anonymou
113130 // Determine the parameter list from the method that is invoked, as delegates without parameters are allowed, but they cannot be replaced by a lambda without parameters.
114131 var parameterList = GetDelegateParameterList ( ( IMethodSymbol ) originalSymbolInfo . Symbol , argumentIndex ) ;
115132
133+ if ( parameterList == null )
134+ {
135+ // This might happen if the call was using params witha type unknown to the analyzer, e.g. params Span<T>.
136+ return false ;
137+ }
138+
116139 // In some cases passing a delegate as an argument to a method is required to call the right overload
117140 // When there is an other overload that takes an expression.
118141 var lambdaExpression = SyntaxFactory . ParenthesizedLambdaExpression (
0 commit comments