{"record":{"id":"2bae1cc7fe6bbe7b","repo":"HandyOrg/HandyControl","slug":"the-property-0-must-be-null-at-this-time","errorCode":null,"errorMessage":"The property {0} 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/Shared/Microsoft.Windows.Shell/Standard/Verify.cs","lineNumber":102,"sourceCode":"    [SuppressMessage(\"Microsoft.Performance\", \"CA1811:AvoidUncalledPrivateCode\")]\n    public static void PropertyIsNotNull<T>(T obj, string name) where T : class\n    {\n        if (obj == null)\n        {\n            throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, \"The property {0} cannot be null at this time.\", new object[]\n            {\n                name\n            }));\n        }\n    }\n\n    [DebuggerStepThrough]\n    [SuppressMessage(\"Microsoft.Performance\", \"CA1811:AvoidUncalledPrivateCode\")]\n    public static void PropertyIsNull<T>(T obj, string name) where T : class\n    {\n        if (obj != null)\n        {\n            throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, \"The property {0} must be null at this time.\", new object[]\n            {\n                name\n            }));\n        }\n    }\n\n    [SuppressMessage(\"Microsoft.Performance\", \"CA1811:AvoidUncalledPrivateCode\")]\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    [DebuggerStepThrough]\n    [SuppressMessage(\"Microsoft.Performance\", \"CA1811:AvoidUncalledPrivateCode\")]","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/HandyOrg/HandyControl/blob/2c0875ebd67326e0c67282967e3e809c69282fee/src/Shared/Microsoft.Windows.Shell/Standard/Verify.cs#L84-L120","documentation":"Verify.PropertyIsNull throws InvalidOperationException when a property that must currently be null is NOT null. It enforces lifecycle state: the object is being used at a point where the property should already have been cleared or never set.","triggerScenarios":"Re-entering or re-calling a lifecycle API (Initialize/Attach/Bind) whose implementation calls Verify.PropertyIsNull(field, propertyName) while the backing property still holds a previous value.","commonSituations":"Double initialization of a control/window object, forgetting to Detach/Dispose before re-attaching, reentrancy during shutdown, caching a stale reference.","solutions":["Clear/reset the property (or dispose and recreate the object) before calling the API again.","Ensure the lifecycle order: detach/dispose the previous state before re-initializing.","Guard the call site: only invoke when the property is null (e.g. if (obj.Prop == null) obj.Initialize(...))."],"exampleFix":"// before\nwindow.Attach(newSource); // InvalidOperationException: The property Source must be null at this time.\n// after\nwindow.Detach();\nwindow.Attach(newSource);","handlingStrategy":"type-guard","validationCode":"if (obj.Source != null)\n    obj.Detach(); // reset state before re-initializing","typeGuard":"static bool IsClean(T obj) => obj?.Source == null;","tryCatchPattern":"try { obj.Attach(source); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"must be null at this time\")) { obj.Detach(); obj.Attach(source); }","preventionTips":["Never call Attach/Initialize twice without Detach/Dispose in between.","Track object lifecycle state explicitly (flags or state machine).","Dispose objects instead of reusing them across lifecycles."],"tags":["invalid-state","lifecycle","dotnet"],"backgroundTag":"invalid-state-transition","analyzedSha":"2c0875ebd67326e0c67282967e3e809c69282fee","analyzedAt":"2026-09-14T14:45:29.754Z","contentChangedAt":"2026-09-14T14:45:29.754Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}