{"record":{"id":"38d9f0a641bca47f","repo":"microsoft/aspire","slug":"the-value-cannot-be-negative","errorCode":null,"errorMessage":"The value cannot be negative.","messagePattern":"The value cannot be negative\\.","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Azure.Sandboxes/AzureSandboxesExtensions.cs","lineNumber":427,"sourceCode":"            }\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        {\n            return;\n        }\n\n        if (value < TimeSpan.Zero)\n        {\n            throw new ArgumentOutOfRangeException(paramName, \"The value cannot be negative.\");\n        }\n\n        if (value.Value.Ticks % TimeSpan.TicksPerSecond != 0)\n        {\n            throw new ArgumentException(\"The value must use whole-second precision.\", paramName);\n        }\n\n        if (maximum is not null && value > maximum)\n        {\n            throw new ArgumentOutOfRangeException(paramName, $\"The value cannot exceed {maximum}.\");\n        }\n    }\n\n    private static void ValidateOptionalEnum<TEnum>(TEnum? value, string paramName)\n        where TEnum : struct, Enum\n    {\n        if (value is not null && !Enum.IsDefined(value.Value))\n        {","sourceCodeStart":409,"sourceCodeEnd":445,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure.Sandboxes/AzureSandboxesExtensions.cs#L409-L445","documentation":"ValidateOptionalWholeSecondDuration rejects negative TimeSpan values passed as optional duration options (e.g. timeouts) for Azure sandbox publishing. Durations in the sandbox configuration must be zero or positive.","triggerScenarios":"PublishAsAzureSandbox (via ValidateSandboxOptions) given an options duration property set to TimeSpan.FromSeconds(-5) or TimeSpan.FromMinutes(-1), or the default TimeSpan value computed from a negative input.","commonSituations":"Computing a timeout as target time minus current time (which can go negative); reading a duration from config where a negative number was supplied; using TimeSpan default arithmetic that underflows.","solutions":["Set the duration to a non-negative TimeSpan value","Clamp with TimeSpan.FromTicks(Math.Max(0, value.Ticks)) before passing options","Fix the computation/config source that produced the negative value"],"exampleFix":"// before\nvar options = new AzureSandboxOptions { IdleTimeout = TimeSpan.FromSeconds(-10) };\n// after\nvar options = new AzureSandboxOptions { IdleTimeout = TimeSpan.FromSeconds(10) };","handlingStrategy":"validation","validationCode":"if (options.IdleTimeout is { } t && t < TimeSpan.Zero) throw new ArgumentException(\"Duration must be non-negative\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Clamp computed durations with Math.Max(TimeSpan.Zero, value)","Never derive durations from time differences without clamping","Validate config-parsed durations before assigning"],"tags":["validation","arguments","timespan","azure-sandbox"],"backgroundTag":"argument-out-of-range","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T09:17:21.228Z"}