{"record":{"id":"b8534dbf86163f8e","repo":"dotnet/wpf","slug":"the-property-name-cannot-be-null-at-this-time","errorCode":null,"errorMessage":"The property {name} 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/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Standard/Verify.cs","lineNumber":138,"sourceCode":"        /// <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.\");\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]","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Standard/Verify.cs#L120-L156","documentation":"Verify.PropertyIsNotNull<T> asserts that an instance property is initialized, throwing InvalidOperationException (not ArgumentException, since this is object-state validation, not argument validation) when the property is null. The message names the offending property via string interpolation.","triggerScenarios":"Calling Verify.PropertyIsNotNull(obj, name) where obj is null — e.g. asserting this.SomeService != null before use when the property was never assigned (initializer not run, constructor skipped, or XAML/load path not executed yet).","commonSituations":"Accessing a WPF component property before template/load initialization completes; using a class before its constructor finished; lazy property that was expected to be set by a prior step.","solutions":["Initialize the property in the constructor or via proper initialization before the guarded call.","Delay the operation until initialization is complete (e.g. wait for Loaded event in WPF).","Use lazy initialization or a factory to guarantee non-null.","Check the interpolated property name in the message to find which property needs initialization."],"exampleFix":"// before\nVerify.PropertyIsNotNull(this.Document, nameof(this.Document));\nDocument.DoWork();\n// after\nif (this.Document == null) this.Document = new Document();\nVerify.PropertyIsNotNull(this.Document, nameof(this.Document));","handlingStrategy":"validation","validationCode":"if (this.Document == null)\n    throw new InvalidOperationException(\"Initialize Document before use\");\nVerify.PropertyIsNotNull(this.Document, nameof(this.Document));","typeGuard":"static bool IsInitialized<T>(T prop) where T : class => prop is not null;","tryCatchPattern":"try {\n    Verify.PropertyIsNotNull(this.Document, nameof(this.Document));\n} catch (InvalidOperationException ex) {\n    log.Error(ex.Message);\n    InitializeDocument();\n}","preventionTips":["Initialize all required properties in constructors or Initialize methods.","In WPF, defer property access until after Loaded/template application.","Use lazy<T> for expensive required properties."],"tags":["wpf","null-check","state-validation","initialization"],"backgroundTag":"null-argument","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"}