{"record":{"id":"621e7dd6b3757b58","repo":"microsoft/semantic-kernel","slug":"nameof-executionparameters-operationselectionpred","errorCode":null,"errorMessage":"{nameof(executionParameters.OperationSelectionPredicate)} and {nameof(executionParameters.OperationsToExclude)} cannot be used together.","messagePattern":"(.+?) and (.+?) cannot be used together\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Functions/Functions.OpenApi/OpenApiKernelPluginFactory.cs","lineNumber":456,"sourceCode":"        }\n\n        logger.LogInformation(\"\"\"Operation name \"{OperationId}\" converted to \"{Result}\" to comply with SK Function name requirements. Use \"{Result}\" when invoking function.\"\"\", operationId, result, result);\n\n        return result;\n    }\n\n    /// <summary>\n    /// Selects operations to parse and import.\n    /// </summary>\n    /// <param name=\"context\">Operation selection context.</param>\n    /// <param name=\"executionParameters\">Execution parameters.</param>\n    /// <returns>True if the operation should be selected; otherwise, false.</returns>\n    private static bool SelectOperations(OperationSelectionPredicateContext context, OpenApiFunctionExecutionParameters? executionParameters)\n    {\n#pragma warning disable CS0618 // Type or member is obsolete\n        if (executionParameters?.OperationSelectionPredicate is not null && executionParameters?.OperationsToExclude is { Count: > 0 })\n        {\n            throw new ArgumentException($\"{nameof(executionParameters.OperationSelectionPredicate)} and {nameof(executionParameters.OperationsToExclude)} cannot be used together.\");\n        }\n\n        if (executionParameters?.OperationSelectionPredicate is { } predicate)\n        {\n            return predicate(context);\n        }\n\n        return !executionParameters?.OperationsToExclude.Contains(context.Id ?? string.Empty) ?? true;\n#pragma warning restore CS0618 // Type or member is obsolete\n    }\n\n    /// <summary>\n    /// Converts the parameter type to a C# <see cref=\"Type\"/> object.\n    /// </summary>\n    /// <param name=\"parameter\">The REST API parameter.</param>\n    private static Type? ConvertParameterDataType(RestApiParameter parameter)\n    {\n        return parameter.Type switch","sourceCodeStart":438,"sourceCodeEnd":474,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/src/Functions/Functions.OpenApi/OpenApiKernelPluginFactory.cs#L438-L474","documentation":"SelectOperations refuses an OpenApiFunctionExecutionParameters instance that sets BOTH OperationSelectionPredicate and a non-empty OperationsToExclude. They are mutually exclusive selection mechanisms (a custom predicate vs. an exclusion list), and both are marked obsolete (the surrounding #pragma disables CS0618). The parser will not guess which wins, so it throws ArgumentException at plugin-creation time.","triggerScenarios":"Constructing OpenApiFunctionExecutionParameters with OperationSelectionPredicate = somePredicate AND OperationsToExclude = { \"op1\", ... }, then passing it to OpenApiKernelPluginFactory.CreateFromOpenApiAsync / KernelPluginFactory.CreateFromOpenApiAsync.","commonSituations":"Migrating code that used OperationsToExclude and then adding a custom OperationSelectionPredicate without removing the old list; copy-paste from two samples; or a refactor that left both fields populated.","solutions":["Keep only ONE selection mechanism: if you have a predicate, clear OperationsToExclude (set to null/empty); if you only need to exclude, remove the predicate.","Prefer OperationSelectionPredicate and fold the exclusion list into it (e.g. predicate returns false for excluded ids), since OperationsToExclude is obsolete.","Re-run plugin creation after removing one of the two to confirm the exception is gone."],"exampleFix":"// before\nvar execParams = new OpenApiFunctionExecutionParameters\n{\n    OperationsToExclude = new[] { \"deprecatedOp\" },\n    OperationSelectionPredicate = ctx => ctx.Id != \"secretOp\",\n};\n// after - single mechanism, exclusion folded into the predicate\nvar execParams = new OpenApiFunctionExecutionParameters\n{\n    OperationSelectionPredicate = ctx =>\n        ctx.Id != \"secretOp\" && ctx.Id != \"deprecatedOp\",\n};","handlingStrategy":"validation","validationCode":"static void ValidateExecParams(OpenApiFunctionExecutionParameters p)\n{\n#pragma warning disable CS0618\n    bool hasPredicate = p?.OperationSelectionPredicate is not null;\n    bool hasExclude  = p?.OperationsToExclude is { Count: > 0 };\n#pragma warning restore CS0618\n    if (hasPredicate && hasExclude)\n        throw new ArgumentException(\n            \"Set either OperationSelectionPredicate or OperationsToExclude, not both.\");\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    var plugin = await kernel.CreatePluginFromOpenApiAsync(\"api\", spec, execParams);\n}\ncatch (ArgumentException ex) when (ex.Message.Contains(\"cannot be used together\"))\n{\n    // clear one of the two fields on execParams and retry\n}","preventionTips":["Treat OperationsToExclude as obsolete; fold exclusions into a single OperationSelectionPredicate.","Unit-test your execution-parameters construction to assert only one selector is set.","Watch for CS0618 warnings around these members - they signal the legacy path."],"tags":["openapi","dotnet","configuration","deprecation"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}