diff --git a/src/DependencyInjection/AddServicesAnalyzer.cs b/src/DependencyInjection/AddServicesAnalyzer.cs index 7318b41..607c8be 100644 --- a/src/DependencyInjection/AddServicesAnalyzer.cs +++ b/src/DependencyInjection/AddServicesAnalyzer.cs @@ -62,7 +62,8 @@ static bool IsDDICode(SyntaxNode node, SemanticModel semantic) .Where(x => !IsDDICode(x.Invocation, semantic) && x.Symbol != null) .Select(x => new { x.Invocation, Method = (IMethodSymbol)x.Symbol! }); - bool IsServiceCollectionExtension(IMethodSymbol method) => method.IsExtensionMethod && + bool IsServiceCollectionExtension(IMethodSymbol method) => method != null && + method.IsExtensionMethod && method.ReducedFrom != null && method.ReducedFrom.Parameters.Length > 0 && method.ReducedFrom.Parameters[0].Type.Equals(servicesCollection, SymbolEqualityComparer.Default); @@ -80,6 +81,7 @@ bool IsServiceCollectionExtension(IMethodSymbol method) => method.IsExtensionMet if (!usesAddServices && invocations.Where(x => IsServiceCollectionExtension(x.Method) && + x.Method.ReducedFrom != null && x.Method.ReducedFrom!.GetAttributes().Any(attr => attr.AttributeClass?.Name == "DDIAddServicesAttribute")) .Any()) {