{"record":{"id":"b819d4cda6579e21","repo":"microsoft/aspire","slug":"connector-operations-cannot-contain-null-values","errorCode":null,"errorMessage":"Connector operations cannot contain null values.","messagePattern":"Connector operations cannot contain null values\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Azure.ConnectorNamespace/AzureConnectorNamespaceExtensions.cs","lineNumber":624,"sourceCode":"\n        if (options.Operations is null || options.Operations.Length == 0)\n        {\n            throw new ArgumentException(\n                \"At least one connector operation must be explicitly allow-listed.\",\n                nameof(options));\n        }\n\n        var operationNames = new HashSet<string>(StringComparer.OrdinalIgnoreCase);\n        var connectorDefinition = new AzureConnectorNamespaceMcpConnectorDefinition(\n            connectorName,\n            options.DisplayName,\n            options.Description,\n            connection.Resource);\n        foreach (var operation in options.Operations)\n        {\n            if (operation is null)\n            {\n                throw new ArgumentException(\"Connector operations cannot contain null values.\", nameof(options));\n            }\n\n            ArgumentException.ThrowIfNullOrWhiteSpace(operation.Name);\n            if (!operationNames.Add(operation.Name))\n            {\n                throw new ArgumentException(\n                    $\"Connector operation '{operation.Name}' is configured more than once.\",\n                    nameof(options));\n            }\n\n            connectorDefinition.Operations.Add(new AzureConnectorNamespaceMcpOperationDefinition(\n                operation.Name,\n                operation.DisplayName,\n                operation.Description));\n        }\n\n        builder.Resource.Connectors.Add(connectorDefinition);\n        return builder;","sourceCodeStart":606,"sourceCodeEnd":642,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure.ConnectorNamespace/AzureConnectorNamespaceExtensions.cs#L606-L642","documentation":"While building the connector definition, WithConnector iterates options.Operations and throws this ArgumentException if any element is null. A null operation has no name or behavior, so the library rejects it up front rather than producing an invalid Bicep/resource definition.","triggerScenarios":"Passing an Operations array that contains a null element, e.g. Operations = new AzureConnectorNamespaceConnectorOperation?[] { null } or a collection built with LINQ that can produce null entries.","commonSituations":"Array initializers with placeholder nulls; deserialized config where an operation object failed to bind; union of multiple operation lists containing nulls.","solutions":["Remove null entries from options.Operations before calling WithConnector.","Use collection expressions or LINQ .Where(op => op is not null) to filter the list.","Fix the source (config binding or factory) that produces null operation objects."],"exampleFix":"// before\nOperations = new[] { op1, null, op2 }\n// after\nOperations = new[] { op1, op2 }","handlingStrategy":"type-guard","validationCode":"if (options.Operations.Any(op => op is null))\n{\n    throw new InvalidOperationException(\"Operations contains null entries.\");\n}","typeGuard":"bool HasNullOperation(IEnumerable<AzureConnectorNamespaceConnectorOperation?> ops) => ops.Any(op => op is null);","tryCatchPattern":"try { builder.WithConnector(options); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"null values\"))\n{\n    // filter nulls from options.Operations and retry\n}","preventionTips":["Filter collections with .Where(op => op is not null) before assignment.","Avoid array initializers with placeholder nulls.","Check deserialization results for null elements."],"tags":["azure","connector","null","argument"],"backgroundTag":"null-argument","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}