{"record":{"id":"0cda949ef85c4721","repo":"dotnet/wpf","slug":"argumentnullexception-name","errorCode":null,"errorMessage":"ArgumentNullException(name)","messagePattern":"ArgumentNullException\\(name\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/Verify.cs","lineNumber":64,"sourceCode":"            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        }\n\n        /// <summary>\n        /// Verifies the specified expression is true.  Throws an ArgumentException if it's not.\n        /// </summary>\n        /// <param name=\"expression\">The expression to be verified as true.</param>\n        /// <param name=\"name\">Name of the parameter to include in the ArgumentException.</param>\n        /// <param name=\"message\">The message to include in the ArgumentException.</param>\n        public static void IsTrue(bool expression, string name, string message)\n        {\n            if (!expression)\n            {\n                throw new ArgumentException(message, name);\n            }\n        }\n\n        /// <summary>","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/Verify.cs#L46-L82","documentation":"Verify.IsNotNull<T>(T obj, string name) throws ArgumentNullException(name) when the argument is a null reference. It is a lightweight null-check helper for reference types (constraint 'where T : class') used across WindowsBase to fail fast with the offending parameter name. The exception carries no custom message - only the parameter name.","triggerScenarios":"Passing null as 'obj' to any internal API that calls Verify.IsNotNull (e.g. null event args, null dependency object, null resource).","commonSituations":"WPF event handlers or callbacks receiving null references from misconfigured XAML or templates; factory methods returning null; optional parameters passed as null where the library doesn't permit it.","solutions":["Read the ParamName on the ArgumentNullException from the stack trace to find which argument was null and stop passing null.","Add your own null check with a descriptive message before calling the API.","Initialize the object properly (constructor, XAML resource, factory) rather than defaulting to null.","If null is a valid state on your side, guard the call site with an if (obj != null) check."],"exampleFix":"// before\ntarget.DoSomething(null); // ArgumentNullException: name\n// after\nif (value == null) throw new ArgumentNullException(nameof(value), \"value is required\");\ntarget.DoSomething(value);","handlingStrategy":"validation","validationCode":"if (obj is null)\n    throw new ArgumentNullException(nameof(obj), \"obj must not be null before calling this API.\");","typeGuard":"bool NotNull<T>([NotNullWhen(true)] T? obj) where T : class => obj is not null;","tryCatchPattern":"try\n{\n    LibraryCall(obj);\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"obj\")\n{\n    logger.LogError(\"Required argument {Param} was null\", ex.ParamName);\n    throw;\n}","preventionTips":["Enable nullable reference types so null flows are caught at compile time","Null-check at public boundaries with descriptive messages","Never return null from factories expected to produce objects","Guard optional values before passing them into WPF APIs"],"tags":["null-argument","argument-validation","wpf"],"backgroundTag":"null-argument","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"}