{"record":{"id":"836ebe2c5e4f0702","repo":"microsoft/aspire","slug":"must-not-be-zero-guard","errorCode":null,"errorMessage":"Must not be zero","messagePattern":"Must not be zero","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Vendoring/OpenTelemetry.Instrumentation.StackExchangeRedis/Shared/Guard.cs","lineNumber":130,"sourceCode":"        }\n#pragma warning restore CS8777 // Parameter must have a non-null value when exiting.\n\n        /// <summary>\n        /// Throw an exception if the value is zero.\n        /// </summary>\n        /// <param name=\"value\">The value to check.</param>\n        /// <param name=\"message\">The message to use in the thrown exception.</param>\n        /// <param name=\"paramName\">The parameter name to use in the thrown exception.</param>\n        [DebuggerHidden]\n        [MethodImpl(MethodImplOptions.AggressiveInlining)]\n        public static void ThrowIfZero(int value, string message = \"Must not be zero\", [CallerArgumentExpression(nameof(value))] string? paramName = null)\n        {\n#if NET\n            ArgumentOutOfRangeException.ThrowIfZero(value, paramName);\n#else\n            if (value == 0)\n            {\n                throw new ArgumentException(message, paramName);\n            }\n#endif\n        }\n\n        /// <summary>\n        /// Throw an exception if the value is negative.\n        /// </summary>\n        /// <param name=\"value\">The value to check.</param>\n        /// <param name=\"message\">The message to use in the thrown exception.</param>\n        /// <param name=\"paramName\">The parameter name to use in the thrown exception.</param>\n        [DebuggerHidden]\n        [MethodImpl(MethodImplOptions.AggressiveInlining)]\n        public static void ThrowIfNegative(int value, string message = \"Must not be negative\", [CallerArgumentExpression(nameof(value))] string? paramName = null)\n        {\n            if (value < 0)\n            {\n                throw new ArgumentOutOfRangeException(paramName, message);\n            }","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Vendoring/OpenTelemetry.Instrumentation.StackExchangeRedis/Shared/Guard.cs#L112-L148","documentation":"Guard.ThrowIfZero validates that an argument is not exactly zero, throwing ArgumentException with 'Must not be zero' when it is. It's a vendored guard utility used by the StackExchangeRedis instrumentation to fail fast on nonsensical zero values (e.g. zero-length buffers or zero-capacity settings). On .NET 6+ it delegates to ArgumentOutOfRangeException.ThrowIfZero, which throws ArgumentOutOfRangeException instead.","triggerScenarios":"Calling Guard.ThrowIfZero(value) with value == 0; typically via instrumented paths that validate numeric parameters (counts, sizes, ports) before use.","commonSituations":"Passing a variable that defaulted to 0 instead of a real value; forgetting to initialize a size/capacity field; parsing config that yielded 0 when unset.","solutions":["Inspect the argument named in the exception and ensure a non-zero value is provided before the call.","Fix the upstream default or initializer so the value is populated with a meaningful value.","Validate the value yourself before calling and short-circuit with a clearer error.","If zero is legitimately allowed at your call site, remove the ThrowIfZero check or handle it before invoking."],"exampleFix":"// before\nGuard.ThrowIfZero(port, nameof(port)); // port defaults to 0\n// after\nif (port == 0) { port = 6379; }\nGuard.ThrowIfZero(port, nameof(port));","handlingStrategy":"validation","validationCode":"if (value == 0) throw new ArgumentException(\"value must be non-zero\", nameof(value));","typeGuard":null,"tryCatchPattern":"catch (ArgumentException ex) when (ex.ParamName == paramName) { /* supply fallback or report config error */ }","preventionTips":["Initialize numeric settings with non-zero defaults.","Validate config at startup before constructing instrumentation.","Never pass raw parsed values without checking for 0/empty."],"tags":["argument-validation","guard","argument-exception"],"backgroundTag":"invalid-argument-value","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"}