{"record":{"id":"65d486f2b5340d1f","repo":"microsoft/aspire","slug":"the-value-must-use-whole-second-precision","errorCode":null,"errorMessage":"The value must use whole-second precision.","messagePattern":"The value must use whole-second precision\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Azure.Sandboxes/AzureSandboxesExtensions.cs","lineNumber":432,"sourceCode":"            }\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        {\n            throw new ArgumentException($\"'{value}' is not a valid {typeof(TEnum).Name} value.\", paramName);\n        }\n    }\n\n    private static void EnsureSandboxPublisherValidationAdded(IDistributedApplicationBuilder builder)","sourceCodeStart":414,"sourceCodeEnd":450,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure.Sandboxes/AzureSandboxesExtensions.cs#L414-L450","documentation":"Optional duration options for Azure sandbox publishing must use whole-second precision. Sub-second values (milliseconds or ticks) cannot be represented in the Azure sandbox configuration, so any TimeSpan with a fractional-second component is rejected.","triggerScenarios":"ValidateSandboxOptions receives e.g. TimeSpan.FromMilliseconds(1500) or TimeSpan.FromSeconds(1.5) for a duration option when calling PublishAsAzureSandbox.","commonSituations":"Passing a measured/elapsed duration that includes milliseconds; converting from a config value expressed in milliseconds; using TimeSpan.FromSeconds with a double literal like 2.5.","solutions":["Round the value to whole seconds before passing it, e.g. TimeSpan.FromSeconds(Math.Round(value.TotalSeconds))","Use TimeSpan.FromSeconds(2) instead of TimeSpan.FromSeconds(2.5)","Express the duration in seconds as an integer in your configuration"],"exampleFix":"// before\nvar options = new AzureSandboxOptions { IdleTimeout = TimeSpan.FromSeconds(1.5) };\n// after\nvar options = new AzureSandboxOptions { IdleTimeout = TimeSpan.FromSeconds(2) };","handlingStrategy":"validation","validationCode":"if (value.Ticks % TimeSpan.TicksPerSecond != 0) value = TimeSpan.FromSeconds(Math.Round(value.TotalSeconds));","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Construct TimeSpans with integer seconds, not doubles","Round measured durations to whole seconds before passing","Avoid milliseconds-based config inputs for these options"],"tags":["validation","arguments","timespan","precision","azure-sandbox"],"backgroundTag":"invalid-duration-format","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"}