diff --git a/src/Kiota.Builder/KiotaBuilder.cs b/src/Kiota.Builder/KiotaBuilder.cs index 66176e81c8..d575562412 100644 --- a/src/Kiota.Builder/KiotaBuilder.cs +++ b/src/Kiota.Builder/KiotaBuilder.cs @@ -955,10 +955,10 @@ x.Parent is CodeIndexer || Parallel.ForEach(unmappedRequestBuilderTypes, parallelOptions, x => { - var parentClass = x.Parent?.Parent as CodeClass; var parentNS = x.Parent?.Parent?.Parent as CodeNamespace; + CodeClass[] exceptions = x.Parent?.Parent is CodeClass parentClass ? [parentClass] : []; x.TypeDefinition = parentNS?.FindChildrenByName(x.Name) - .Except([parentClass]).OfType() // the property method should not reference itself as a return type. + .Except(exceptions)// the property method should not reference itself as a return type. .MinBy(shortestNamespaceOrder); // searching down first because most request builder properties on a request builder are just sub paths on the API if (x.TypeDefinition == null)