{"record":{"id":"d7133c177e4edde8","repo":"microsoft/aspire","slug":"endpoint-options-cannot-contain-null-values","errorCode":null,"errorMessage":"Endpoint options cannot contain null values.","messagePattern":"Endpoint options cannot contain null values\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Azure.Sandboxes/AzureSandboxesExtensions.cs","lineNumber":403,"sourceCode":"        if (options.AutoDeleteEnabled is null &&\n            (options.AutoDeleteInterval is not null || options.AutoDeleteTrigger is not null))\n        {\n            throw new ArgumentException(\n                $\"{nameof(AzureSandboxOptions.AutoDeleteEnabled)} must be set when configuring auto-delete interval or trigger.\",\n                nameof(options));\n        }\n\n        if (options.Endpoints is null)\n        {\n            return;\n        }\n\n        var names = new HashSet<string>(StringComparer.OrdinalIgnoreCase);\n        foreach (var endpoint in options.Endpoints)\n        {\n            if (endpoint is null)\n            {\n                throw new ArgumentException(\"Endpoint options cannot contain null values.\", nameof(options));\n            }\n\n            if (string.IsNullOrWhiteSpace(endpoint.Name))\n            {\n                throw new ArgumentException(\"Endpoint option names cannot be empty.\", nameof(options));\n            }\n\n            if (!names.Add(endpoint.Name))\n            {\n                throw new ArgumentException($\"Endpoint option '{endpoint.Name}' is configured more than once.\", nameof(options));\n            }\n        }\n    }\n\n    private static void ValidateOptionalWholeSecondDuration(TimeSpan? value, string paramName, TimeSpan? maximum = null)\n    {\n        if (value is null)\n        {","sourceCodeStart":385,"sourceCodeEnd":421,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure.Sandboxes/AzureSandboxesExtensions.cs#L385-L421","documentation":"ValidateSandboxOptions in PublishAsAzureSandbox rejects an endpoint options collection that contains a null entry. The library requires every element of AzureSandboxOptions.Endpoints to be a fully populated endpoint descriptor; nulls indicate a half-initialized options object that would produce broken Azure sandbox endpoint configuration.","triggerScenarios":"Calling PublishAsAzureSandbox with options whose Endpoints list literally contains null, e.g. new AzureSandboxOptions { Endpoints = [null] } or building the list programmatically where a null endpoint slipped in.","commonSituations":"Conditional endpoint construction where a variable assigned from config or a factory returns null; array initializers with placeholder nulls to be filled later; deserialization of options from JSON where a null element was preserved.","solutions":["Remove null entries from options.Endpoints before calling PublishAsAzureSandbox","Ensure any endpoint factory/deserialization code never emits null elements","Validate options in your own code with Endpoints.All(e => e is not null) before publishing"],"exampleFix":"// before\nvar options = new AzureSandboxOptions { Endpoints = [null, endpointA] };\nbuilder.PublishAsAzureSandbox(resource, options);\n// after\nvar options = new AzureSandboxOptions { Endpoints = [endpointA] };\nbuilder.PublishAsAzureSandbox(resource, options);","handlingStrategy":"validation","validationCode":"if (options.Endpoints.Any(e => e is null)) throw new ArgumentException(\"Endpoints must not contain nulls\");","typeGuard":"bool HasNoNullEndpoints(AzureSandboxOptions o) => o.Endpoints.All(e => e is not null);","tryCatchPattern":null,"preventionTips":["Build endpoint lists with collection expressions over non-null values","Avoid filling placeholder nulls in options arrays","Run options validation before calling PublishAsAzureSandbox"],"tags":["validation","arguments","azure-sandbox","endpoints"],"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"}