{"record":{"id":"e046bcb7133d01df","repo":"dotnet/wpf","slug":"sr-verify-neithernullnorempty","errorCode":null,"errorMessage":"SR.Verify_NeitherNullNorEmpty","messagePattern":"SR\\.Verify_NeitherNullNorEmpty","errorType":"validation","errorClass":"System.ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/Verify.cs","lineNumber":48,"sourceCode":"            {\n                throw new InvalidOperationException(SR.Format(SR.Verify_ApartmentState, requiredState));\n            }\n        }\n\n        /// <summary>\n        /// Ensure that an argument is neither null nor empty.\n        /// </summary>\n        /// <param name=\"value\">The string to validate.</param>\n        /// <param name=\"name\">The name of the parameter that will be presented if an exception is thrown.</param>\n        public static void IsNeitherNullNorEmpty(string value, string name)\n        {\n            // catch caller errors, mixing up the parameters.  Name should never be empty.\n            Debug.Assert(!string.IsNullOrEmpty(name));\n\n            // Notice that ArgumentNullException and ArgumentException take the parameters in opposite order :P\n            if (value == null)\n            {\n                throw new ArgumentNullException(name, SR.Verify_NeitherNullNorEmpty);\n            }\n            if (value == \"\")\n            {\n                throw new ArgumentException(SR.Verify_NeitherNullNorEmpty, name);\n            }\n        }\n\n        /// <summary>Verifies that an argument is not null.</summary>\n        /// <typeparam name=\"T\">Type of the object to validate.  Must be a class.</typeparam>\n        /// <param name=\"obj\">The object to validate.</param>\n        /// <param name=\"name\">The name of the parameter that will be presented if an exception is thrown.</param>\n        public static void IsNotNull<T>(T obj, string name) where T : class\n        {\n            if (obj == null)\n            {\n                throw new ArgumentNullException(name);\n            }\n        }","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/Verify.cs#L30-L66","documentation":"Verify.IsNeitherNullNorEmpty rejects a string argument that is null (ArgumentNullException) or the empty string \"\" (ArgumentException), with the parameter's name attached. The library treats an empty string as indistinguishable from a missing value, so callers must pass a real, non-empty value. The doc comment notes the parameter 'name' should never itself be empty - that would indicate a caller bug mixing up parameters.","triggerScenarios":"Passing null or \"\" as the 'value' argument to Verify.IsNeitherNullNorEmpty(value, name) - directly or via wrappers such as Verify.FileExists where the path argument is empty.","commonSituations":"Path/name strings built from configuration or user input that end up empty (missing config key, blank text box, unexpanded environment variable); string fields default-initialized to \"\" instead of null and then validated.","solutions":["Inspect the call stack to identify which named parameter was empty; fix the value source so a real non-empty string is supplied.","Guard before calling: if (string.IsNullOrEmpty(value)) throw/log with context instead of letting the library throw.","Fix configuration/user input defaults so required strings are never empty (use meaningful defaults or fail fast at startup).","If empty is legitimately allowed, don't route through this verify method - check before calling."],"exampleFix":"// before\nVerify.IsNeitherNullNorEmpty(config.OutputPath, \"OutputPath\"); // config.OutputPath == \"\"\n// after\nif (string.IsNullOrEmpty(config.OutputPath))\n    config.OutputPath = DefaultOutputPath; // or fail fast with a clear message\nVerify.IsNeitherNullNorEmpty(config.OutputPath, \"OutputPath\");","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(value))\n    throw new ArgumentException($\"{nameof(value)} must be a non-empty string.\", nameof(value));","typeGuard":"bool IsNonEmpty(string? s) => !string.IsNullOrEmpty(s);","tryCatchPattern":"try\n{\n    LibraryCall(value);\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"value\")\n{\n    logger.LogWarning(\"Required string '{Param}' was null\", ex.ParamName);\n}\ncatch (ArgumentException ex) when (ex.ParamName == \"value\")\n{\n    logger.LogWarning(\"Required string '{Param}' was empty\", ex.ParamName);\n}","preventionTips":["Validate strings with string.IsNullOrEmpty at the boundary where they enter your code","Never default required strings to String.Empty; use null plus explicit handling or a real default","Check config/env values for blank-but-present entries during startup fail-fast","Keep the parameter name in sync (nameof) so exception ParamName stays accurate"],"tags":["argument-validation","null-argument","empty-string","wpf"],"backgroundTag":"empty-required-field","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}