{"record":{"id":"1d1a51c298b9851a","repo":"dotnet/wpf","slug":"the-parameter-must-be-null","errorCode":null,"errorMessage":"The parameter must be null.","messagePattern":"The parameter must be null\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Standard/Verify.cs","lineNumber":129,"sourceCode":"        [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>\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 IsNull<T>(T obj, string name) where T : class\n        {\n            if (null != obj)\n            {\n                throw new ArgumentException(\"The parameter must be null.\", name);\n            }\n        }\n        \n        [DebuggerStepThrough]\n        public static void PropertyIsNotNull<T>(T obj, string name) where T : class\n        {\n            if (null == obj)\n            {\n                throw new InvalidOperationException($\"The property {name} cannot be null at this time.\");\n            }\n        }\n        \n        [DebuggerStepThrough]\n        public static void PropertyIsNull<T>(T obj, string name) where T : class\n        {\n            if (null != obj)\n            {\n                throw new InvalidOperationException($\"The property {name} must be null at this time.\");","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Standard/Verify.cs#L111-L147","documentation":"Verify.IsNull<T> is the inverse of a null check: it asserts that a reference-type argument IS null, throwing ArgumentException if it is not. It is used to enforce that some object has already been released/reset (e.g. a disposed or detached resource must be null).","triggerScenarios":"Calling Verify.IsNull(obj, name) when obj is a live, non-null reference — e.g. asserting a handle/dispatcher/resource was cleared but it was never set to null.","commonSituations":"Teardown/dispose code asserting state reset; refactors that changed cleanup logic so a field is no longer nulled; object reuse without clearing prior references.","solutions":["Set the field/variable to null (or Dispose and null it) before calling Verify.IsNull.","If the object legitimately can be non-null, remove this assertion or replace it with a state check that matches the real contract.","Ensure disposal paths actually run (check for early returns/exceptions skipping cleanup).","Use ex.ParamName to identify which reference was expected to be null."],"exampleFix":"// before\nVerify.IsNull(_sink, nameof(_sink)); // _sink still holds old reference\n// after\n_sink?.Dispose();\n_sink = null;\nVerify.IsNull(_sink, nameof(_sink));","handlingStrategy":"type-guard","validationCode":"if (obj != null)\n    throw new InvalidOperationException($\"{nameof(obj)} must already be null (released)\");\nVerify.IsNull(obj, nameof(obj));","typeGuard":"static bool IsReleased<T>(T obj) where T : class => obj is null;","tryCatchPattern":"try {\n    Verify.IsNull(_resource, nameof(_resource));\n} catch (ArgumentException ex) {\n    (_resource as IDisposable)?.Dispose();\n    _resource = null;\n}","preventionTips":["Always null fields after Dispose in teardown paths.","Keep reset logic in one place (a single Cleanup method) to avoid skipped nulling.","Guard re-entry into initialization code with state flags."],"tags":["argument-validation","wpf","state-assertion","null-check"],"backgroundTag":"invalid-state-transition","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"}