{"record":{"id":"179189aeed551a07","repo":"microsoft/aspire","slug":"must-not-be-null-guard","errorCode":null,"errorMessage":"Must not be null","messagePattern":"Must not be null","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Vendoring/OpenTelemetry.Instrumentation.StackExchangeRedis/Shared/Guard.cs","lineNumber":68,"sourceCode":"    /// Methods for guarding against exception throwing values.\n    /// </summary>\n    internal static class Guard\n    {\n        /// <summary>\n        /// Throw an exception if the value is null.\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 ThrowIfNull([NotNull] object? value, [CallerArgumentExpression(nameof(value))] string? paramName = null)\n        {\n#if NET\n            ArgumentNullException.ThrowIfNull(value, paramName);\n#else\n            if (value is null)\n            {\n                throw new ArgumentNullException(paramName, \"Must not be null\");\n            }\n#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))","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Vendoring/OpenTelemetry.Instrumentation.StackExchangeRedis/Shared/Guard.cs#L50-L86","documentation":"Thrown by Guard.ThrowIfNull in the vendored StackExchangeRedis instrumentation's Guard helper when a required object parameter is null. On NET6+ targets it delegates to ArgumentNullException.ThrowIfNull (standard SDK message); on older targets it throws ArgumentNullException with the message \"Must not be null\". Same contract as 2040 but from the Redis instrumentation.","triggerScenarios":"Calling a StackExchangeRedis instrumentation API (or code it guards) with null for a required parameter, e.g. null IConnectionMultiplexer, null options, or null configuration instance.","commonSituations":"Multiplexer initialization failed or was not awaited before registering the instrumentation; DI returning null for an optional dependency; config object not constructed before use.","solutions":["Check paramName and ensure the referenced argument is initialized before the call.","Verify the Redis connection is successfully created and non-null before passing it to the instrumentation.","Enable nullable reference types to catch the null flow at compile time."],"exampleFix":"// before\nIConnectionMultiplexer? mux = TryConnect(); // may be null\nAddRedisInstrumentation(mux);\n\n// after\nIConnectionMultiplexer mux = TryConnect() ?? throw new InvalidOperationException(\"could not connect to Redis\");\nAddRedisInstrumentation(mux);","handlingStrategy":"validation","validationCode":"if (multiplexer is null)\n{\n    throw new ArgumentNullException(nameof(multiplexer));\n}","typeGuard":"static bool HasMultiplexer([NotNullWhen(true)] IConnectionMultiplexer? mux) => mux is not null;","tryCatchPattern":"try\n{\n    AddRedisInstrumentation(multiplexer);\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"multiplexer\")\n{\n    logger.LogError(ex, \"Redis multiplexer was null; connection likely failed\");\n}","preventionTips":["Await connection establishment before registering the instrumentation","Make DI dependencies required so null injection fails at startup","Check ConnectionFailed events from StackExchange.Redis"],"tags":["argument-null","validation","opentelemetry","redis"],"backgroundTag":"null-argument","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"}