{"record":{"id":"50f3492cb883bc3d","repo":"dotnet/maui","slug":"the-parameter-must-be-null","errorCode":null,"errorMessage":"The parameter must be null.","messagePattern":"The parameter must be null\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Compatibility/Core/src/WPF/Microsoft.Windows.Shell/Standard/Verify.cs","lineNumber":139,"sourceCode":"\t\t\tif (null == obj)\n\t\t\t{\n\t\t\t\tAssert.Fail();\n\t\t\t\tthrow new ArgumentNullException(name);\n\t\t\t}\n\t\t}\n\n\t\t/// <summary>Verifies that an argument is null.</summary>\n\t\t/// <typeparam name=\"T\">Type of the object to validate.  Must be a class.</typeparam>\n\t\t/// <param name=\"obj\">The object to validate.</param>\n\t\t/// <param name=\"name\">The name of the parameter that will be presented if an exception is thrown.</param>\n\t\t[SuppressMessage(\"Microsoft.Performance\", \"CA1811:AvoidUncalledPrivateCode\")]\n\t\t[DebuggerStepThrough]\n\t\tpublic static void IsNull<T>(T obj, string name) where T : class\n\t\t{\n\t\t\tif (null != obj)\n\t\t\t{\n\t\t\t\tAssert.Fail();\n\t\t\t\tthrow new ArgumentException(\"The parameter must be null.\", name);\n\t\t\t}\n\t\t}\n\n\t\t[SuppressMessage(\"Microsoft.Performance\", \"CA1811:AvoidUncalledPrivateCode\")]\n\t\t[DebuggerStepThrough]\n\t\tpublic static void PropertyIsNotNull<T>(T obj, string name) where T : class\n\t\t{\n\t\t\tif (null == obj)\n\t\t\t{\n\t\t\t\tAssert.Fail();\n\t\t\t\tthrow new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, \"The property {0} cannot be null at this time.\", name));\n\t\t\t}\n\t\t}\n\n\t\t[SuppressMessage(\"Microsoft.Performance\", \"CA1811:AvoidUncalledPrivateCode\")]\n\t\t[DebuggerStepThrough]\n\t\tpublic static void PropertyIsNull<T>(T obj, string name) where T : class\n\t\t{","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Compatibility/Core/src/WPF/Microsoft.Windows.Shell/Standard/Verify.cs#L121-L157","documentation":"Verify.IsNull<T> (where T : class) throws ArgumentException when obj is NOT null. It is the inverse of the usual null check — it asserts that the argument must be null at this point. This is used for state-transition guards where a non-null value indicates the object is in the wrong lifecycle state.","triggerScenarios":"Calling a method guarded by Verify.IsNull(obj, name) when obj has already been assigned a non-null reference. The method expects the value to be unset/cleared at the time of the call.","commonSituations":"Calling an Initialize/Set method twice without first clearing the previous value; a dispose-then-reset path where the field was not nulled after disposal; lifecycle ordering where the caller advanced the object state out of order.","solutions":["Ensure the referenced object is set to null before calling the method that requires null.","Check the lifecycle: if the object must be null, verify it has been reset/cleared first.","Restructure to avoid double-initialization; guard the calling code against re-entry."],"exampleFix":"// before\nwindow.Initialize(); // internal reference already set\n\n// after\nwindow.Reset(); // sets internal reference to null\nwindow.Initialize();","handlingStrategy":"validation","validationCode":"// Pre-check: the API requires the reference to be null\nif (obj != null)\n{\n    throw new ArgumentException(\"Reference must be null at this point.\", nameof(obj));\n}\nSomeApi(obj);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Reset references to null before calling lifecycle methods that require a clean state.","Guard against re-entry / double-initialization at the call site.","Document lifecycle ordering requirements for objects with must-be-null preconditions."],"tags":["validation","argument","lifecycle","verify"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}