{"record":{"id":"567a001fcdacbd34","repo":"HandyOrg/HandyControl","slug":"the-property-0-cannot-be-null-at-this-time","errorCode":null,"errorMessage":"The property {0} cannot be null at this time.","messagePattern":"The property (.+?) cannot be null at this time\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Shared/Microsoft.Windows.Shell/Standard/Verify.cs","lineNumber":89,"sourceCode":"    }\n\n    [SuppressMessage(\"Microsoft.Performance\", \"CA1811:AvoidUncalledPrivateCode\")]\n    [DebuggerStepThrough]\n    public static void IsNull<T>(T obj, string name) where T : class\n    {\n        if (obj != null)\n        {\n            throw new ArgumentException(\"The parameter must be null.\", name);\n        }\n    }\n\n    [DebuggerStepThrough]\n    [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    }","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/HandyOrg/HandyControl/blob/2c0875ebd67326e0c67282967e3e809c69282fee/src/Shared/Microsoft.Windows.Shell/Standard/Verify.cs#L71-L107","documentation":"Verify.PropertyIsNotNull throws InvalidOperationException when a property that must currently be initialized is still null. Unlike the argument guards, this signals the OBJECT is in the wrong state, so it uses InvalidOperationException, not ArgumentException.","triggerScenarios":"Accessing a property or method on an object whose implementation calls Verify.PropertyIsNotNull(field, propertyName) while that backing field/property is still null (e.g. using a component before its Initialize/EnsureCreated ran).","commonSituations":"Using a control or shell object before initialization, DI/property injection that never ran, consuming a lazily-created resource before first setup, construction order bugs.","solutions":["Initialize the object/property before use (call the documented Initialize/Create/setup method first).","Check the property for null before accessing dependent members and initialize lazily.","Verify construction/DI wiring so the property is actually populated."],"exampleFix":"// before\nvar hwnd = window.Hwnd; // InvalidOperationException: The property Hwnd cannot be null at this time.\n// after\nwindow.EnsureInitialized();\nvar hwnd = window.Hwnd;","handlingStrategy":"type-guard","validationCode":"if (obj.RequiredProperty == null)\n    obj.Initialize(); // or skip usage until initialized","typeGuard":"static bool IsReady(T obj) => obj?.RequiredProperty != null;","tryCatchPattern":"try { UseComponent(obj); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"cannot be null at this time\")) { obj.Initialize(); UseComponent(obj); }","preventionTips":["Call Initialize/Create before any member access on shell/window objects.","Check initialization order in constructors and DI wiring.","Prefer lazy initialization for properties populated late in the lifecycle."],"tags":["invalid-state","null-check","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"}