{"record":{"id":"dbb13ea4a140936b","repo":"microsoft/aspire","slug":"must-not-be-null-or-empty-guard","errorCode":null,"errorMessage":"Must not be null or empty","messagePattern":"Must not be null or empty","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Vendoring/OpenTelemetry.Instrumentation.StackExchangeRedis/Shared/Guard.cs","lineNumber":88,"sourceCode":"#endif\n        }\n\n        /// <summary>\n        /// Throw an exception if the value is null or empty.\n        /// </summary>\n        /// <param name=\"value\">The value to check.</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 ThrowIfNullOrEmpty([NotNull] string? value, [CallerArgumentExpression(nameof(value))] string? paramName = null)\n#pragma warning disable CS8777 // Parameter must have a non-null value when exiting.\n        {\n#if NET\n            ArgumentException.ThrowIfNullOrEmpty(value, paramName);\n#else\n            if (string.IsNullOrEmpty(value))\n            {\n                throw new ArgumentException(\"Must not be null or empty\", paramName);\n            }\n#endif\n        }\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 null or whitespace.\n        /// </summary>\n        /// <param name=\"value\">The value to check.</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 ThrowIfNullOrWhitespace([NotNull] string? value, [CallerArgumentExpression(nameof(value))] string? paramName = null)\n#pragma warning disable CS8777 // Parameter must have a non-null value when exiting.\n        {\n#if NET\n            ArgumentException.ThrowIfNullOrWhiteSpace(value, paramName);\n#else","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Vendoring/OpenTelemetry.Instrumentation.StackExchangeRedis/Shared/Guard.cs#L70-L106","documentation":"Thrown by Guard.ThrowIfNullOrEmpty in the vendored StackExchangeRedis instrumentation's Guard helper when a required string parameter is null or empty. On .NET targets it delegates to ArgumentException.ThrowIfNullOrEmpty; otherwise it throws ArgumentException with \"Must not be null or empty\". Guards required string values such as names or configuration strings.","triggerScenarios":"Passing null or \"\" to a guarded string parameter, e.g. an empty connection string, empty service name, or unset configuration key read from configuration that defaulted to empty.","commonSituations":"Missing environment variables defaulting to empty; connection strings defined but left blank in appsettings; string interpolation producing \"\" when an upstream value is missing.","solutions":["Supply a valid non-empty value for the argument named in the exception.","Fix the configuration source that yielded the empty string (missing key, blank entry).","Validate with ArgumentException.ThrowIfNullOrEmpty at your own boundary for clearer diagnostics."],"exampleFix":"// before\nvar connStr = configuration[\"Redis:ConnectionString\"]; // null\nUseConnectionString(connStr);\n\n// after\nvar connStr = configuration[\"Redis:ConnectionString\"];\nArgumentException.ThrowIfNullOrEmpty(connStr);\nUseConnectionString(connStr);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(connectionString))\n{\n    throw new ArgumentException(\"Must not be null or empty\", nameof(connectionString));\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    AddRedisInstrumentation(o => o.ConnectionString = connectionString);\n}\ncatch (ArgumentException ex) when (ex.ParamName == \"connectionString\")\n{\n    logger.LogError(ex, \"connection string missing from configuration\");\n}","preventionTips":["Validate required config keys at application startup","Fail fast when an env var or config key is absent instead of defaulting to empty","Log the config key path (not the secret) when validation fails"],"tags":["argument-empty","validation","opentelemetry","redis"],"backgroundTag":"empty-required-field","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"}