{"record":{"id":"93d54a20fb489049","repo":"microsoft/aspire","slug":"the-value-cannot-exceed-maximum","errorCode":null,"errorMessage":"The value cannot exceed {maximum}.","messagePattern":"The value cannot exceed (.+?)\\.","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Azure.Sandboxes/AzureSandboxesExtensions.cs","lineNumber":437,"sourceCode":"    {\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        {\n            throw new ArgumentException($\"'{value}' is not a valid {typeof(TEnum).Name} value.\", paramName);\n        }\n    }\n\n    private static void EnsureSandboxPublisherValidationAdded(IDistributedApplicationBuilder builder)\n    {\n        if (builder.Services.Any(static descriptor => descriptor.ServiceType == typeof(AzureSandboxPipelineStepMarker)))\n        {\n            return;\n        }","sourceCodeStart":419,"sourceCodeEnd":455,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure.Sandboxes/AzureSandboxesExtensions.cs#L419-L455","documentation":"Optional duration options have an upper bound enforced via the maximum parameter in ValidateOptionalWholeSecondDuration. When the supplied TimeSpan is valid in sign and precision but larger than the allowed maximum, an ArgumentOutOfRangeException names the parameter and states the limit.","triggerScenarios":"PublishAsAzureSandbox given a duration option exceeding the library-defined maximum, e.g. an idle timeout larger than the supported cap (value > maximum check).","commonSituations":"Setting very long timeouts assuming they are unbounded; copying a timeout from another product's docs; misreading seconds as minutes so the value overshoots the max.","solutions":["Reduce the duration to at or below the stated maximum in the message","Check the option's XML docs/readme for the documented maximum","Clamp before assignment: value > max ? max : value"],"exampleFix":"// before\nvar options = new AzureSandboxOptions { IdleTimeout = TimeSpan.FromHours(48) }; // exceeds max\n// after\nvar options = new AzureSandboxOptions { IdleTimeout = TimeSpan.FromHours(4) }; // within maximum","handlingStrategy":"validation","validationCode":"if (value > maximum) value = maximum;","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check documented maximums for duration options","Clamp durations to the documented cap before assignment","Watch units (seconds vs minutes) when copying timeout values"],"tags":["validation","arguments","timespan","azure-sandbox"],"backgroundTag":"value-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"}