{"record":{"id":"0af727403a675f9c","repo":"dotnet/wpf","slug":"the-property-name-must-be-null-at-this-time","errorCode":null,"errorMessage":"The property {name} must be null at this time.","messagePattern":"The property (.+?) must be null at this time\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Standard/Verify.cs","lineNumber":147,"sourceCode":"                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.\");\n            }\n        }\n\n        /// <summary>\n        /// Verifies the specified statement is true.  Throws an ArgumentException if it's not.\n        /// </summary>\n        /// <param name=\"statement\">The statement to be verified as true.</param>\n        /// <param name=\"name\">Name of the parameter to include in the ArgumentException.</param>    \n        [DebuggerStepThrough]\n        public static void IsTrue(bool statement, string name)\n        {\n            if (!statement)\n            {\n                throw new ArgumentException(\"\", name);\n            }\n        }\n\n        /// <summary>","sourceCodeStart":129,"sourceCodeEnd":165,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Standard/Verify.cs#L129-L165","documentation":"Verify.PropertyIsNull<T> is the inverse assertion for properties: it demands that the property currently be null and throws InvalidOperationException if a value is still present. It enforces lifecycle state — typically that a resource was released or not yet created.","triggerScenarios":"Calling Verify.PropertyIsNull(obj, name) while the property still holds a reference — e.g. re-initializing or disposing a component that asserts a previous instance was cleared, but cleanup didn't null it.","commonSituations":"Double initialization of a singleton property; Dispose patterns where the field reset was removed; re-entering setup code after a partial failure.","solutions":["Null out the property (after disposing) before re-running the guarded code path.","Add proper Dispose/cleanup so the property is cleared on teardown.","If re-initialization is legal, relax or remove this assertion and use an explicit state flag instead.","Check the interpolated property name in the message to find the stale reference."],"exampleFix":"// before\nVerify.PropertyIsNull(this.Handler, nameof(this.Handler)); // still set\nthis.Handler = CreateHandler();\n// after\n(this.Handler as IDisposable)?.Dispose();\nthis.Handler = null;\nVerify.PropertyIsNull(this.Handler, nameof(this.Handler));\nthis.Handler = CreateHandler();","handlingStrategy":"validation","validationCode":"if (this.Handler != null)\n    throw new InvalidOperationException(\"Handler must be released before re-initialization\");\nVerify.PropertyIsNull(this.Handler, nameof(this.Handler));","typeGuard":"static bool IsCleared<T>(T prop) where T : class => prop is null;","tryCatchPattern":"try {\n    Verify.PropertyIsNull(this.Handler, nameof(this.Handler));\n} catch (InvalidOperationException ex) {\n    (this.Handler as IDisposable)?.Dispose();\n    this.Handler = null;\n}","preventionTips":["Make Dispose idempotent and always null out owned properties.","Prevent double initialization with an initialized flag.","Route all teardown through a single cleanup path."],"tags":["wpf","state-validation","lifecycle","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"}