{"record":{"id":"8d966acfbd08e12c","repo":"dotnet/wpf","slug":"the-parameter-must-not-be-the-default-value","errorCode":null,"errorMessage":"The parameter must not be the default value.","messagePattern":"The parameter must not be the default value\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Standard/Verify.cs","lineNumber":103,"sourceCode":"            {\n                throw new ArgumentNullException(name, errorMessage);\n            }\n            if (\"\" == value.Trim())\n            {\n                throw new ArgumentException(errorMessage, 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        [DebuggerStepThrough]\n        public static void IsNotDefault<T>(T obj, string name) where T : struct\n        {\n            if (default(T).Equals(obj))\n            {\n                throw new ArgumentException(\"The parameter must not be the default value.\", 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        [DebuggerStepThrough]\n        public static void IsNotNull<T>(T obj, string name) where T : class\n        {\n            if (null == obj)\n            {\n                throw new ArgumentNullException(name);\n            }\n        }\n\n        /// <summary>Verifies that an argument is null.</summary>\n        /// <typeparam name=\"T\">Type of the object to validate.  Must be a class.</typeparam>","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Standard/Verify.cs#L85-L121","documentation":"Verify.IsNotDefault<T> validates that a value-type argument does not equal default(T) (e.g. 0, Guid.Empty, DateTime.MinValue). If obj equals the type's default, it throws ArgumentException with the parameter name. It prevents 'unset' struct values from flowing into APIs that require meaningful data.","triggerScenarios":"Calling Verify.IsNotDefault(obj, name) where obj == default(T), e.g. an uninitialized Guid.NewGuid field, a zero id, or a struct default-initialized by deserialization.","commonSituations":"Passing Guid.Empty as an identifier, zero handles/ids from failed lookups, structs default-constructed instead of initialized.","solutions":["Check obj.Equals(default(T)) before the call and initialize the struct properly.","For Guids, ensure Guid.NewGuid() or a parsed value is assigned rather than relying on field initialization.","Consider making the parameter nullable (T?) so 'unset' is explicit, or change the API contract.","Read ex.ParamName to find which struct argument was default."],"exampleFix":"// before\nGuid id; // default Guid.Empty\nVerify.IsNotDefault(id, nameof(id));\n// after\nGuid id = Guid.NewGuid();\nif (id == Guid.Empty) throw new ArgumentException(\"id not initialized\", nameof(id));\nVerify.IsNotDefault(id, nameof(id));","handlingStrategy":"validation","validationCode":"if (obj.Equals(default(T)))\n    throw new ArgumentException($\"{nameof(obj)} must not be default(T)\", nameof(obj));\nVerify.IsNotDefault(obj, nameof(obj));","typeGuard":"static bool IsSet<T>(T v) where T : struct => !default(T).Equals(v);","tryCatchPattern":"try {\n    Verify.IsNotDefault(id, nameof(id));\n} catch (ArgumentException ex) when (ex.ParamName == nameof(id)) {\n    id = GenerateNewId();\n}","preventionTips":["Initialize struct fields at declaration or in constructors.","Use Guid.NewGuid() rather than relying on field defaults for ids.","Prefer nullable<T> or explicit HasValue flags when 'unset' is a legal state."],"tags":["argument-validation","wpf","value-types","default-value"],"backgroundTag":"invalid-argument-value","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"}