{"record":{"id":"f7bbb42e426ccb61","repo":"dotnet/maui","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/Compatibility/Core/src/WPF/Microsoft.Windows.Shell/Standard/Verify.cs","lineNumber":150,"sourceCode":"\t\t[SuppressMessage(\"Microsoft.Performance\", \"CA1811:AvoidUncalledPrivateCode\")]\n\t\t[DebuggerStepThrough]\n\t\tpublic static void IsNull<T>(T obj, string name) where T : class\n\t\t{\n\t\t\tif (null != obj)\n\t\t\t{\n\t\t\t\tAssert.Fail();\n\t\t\t\tthrow new ArgumentException(\"The parameter must be null.\", name);\n\t\t\t}\n\t\t}\n\n\t\t[SuppressMessage(\"Microsoft.Performance\", \"CA1811:AvoidUncalledPrivateCode\")]\n\t\t[DebuggerStepThrough]\n\t\tpublic static void PropertyIsNotNull<T>(T obj, string name) where T : class\n\t\t{\n\t\t\tif (null == obj)\n\t\t\t{\n\t\t\t\tAssert.Fail();\n\t\t\t\tthrow new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, \"The property {0} cannot be null at this time.\", name));\n\t\t\t}\n\t\t}\n\n\t\t[SuppressMessage(\"Microsoft.Performance\", \"CA1811:AvoidUncalledPrivateCode\")]\n\t\t[DebuggerStepThrough]\n\t\tpublic static void PropertyIsNull<T>(T obj, string name) where T : class\n\t\t{\n\t\t\tif (null != obj)\n\t\t\t{\n\t\t\t\tAssert.Fail();\n\t\t\t\tthrow new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, \"The property {0} must be null at this time.\", name));\n\t\t\t}\n\t\t}\n\n\t\t/// <summary>\n\t\t/// Verifies the specified statement is true.  Throws an ArgumentException if it's not.\n\t\t/// </summary>\n\t\t/// <param name=\"statement\">The statement to be verified as true.</param>","sourceCodeStart":132,"sourceCodeEnd":168,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Compatibility/Core/src/WPF/Microsoft.Windows.Shell/Standard/Verify.cs#L132-L168","documentation":"Verify.PropertyIsNotNull<T> (where T : class) throws InvalidOperationException (not ArgumentException) when the property value is null. Unlike the argument guards, this is a state guard — it signals that the object's current state is invalid because a required property has not been set. The message is formatted with the property name.","triggerScenarios":"Calling a method that internally asserts Verify.PropertyIsNotNull(_someProperty, \"SomeProperty\") before the property has been assigned. The guard fires because a precondition on internal state was violated.","commonSituations":"Using an object before its required properties are set (e.g. calling Show before Title is assigned); a dependency property or service was never injected; initialization ran partially and a setter was skipped.","solutions":["Set the required property before invoking the operation that depends on it.","Verify initialization order — ensure all required properties are assigned in the constructor or init path.","Add a state check in your own code (if (obj.Property == null) throw) earlier with a clearer message."],"exampleFix":"// before\nchromeWindow.ApplyChrome();\n\n// after\nif (chromeWindow.ChromeInfo == null)\n{\n    throw new InvalidOperationException(\"ChromeInfo must be set before applying.\");\n}\nchromeWindow.ApplyChrome();","handlingStrategy":"validation","validationCode":"// Pre-check: required property must be set before the operation\nif (obj.RequiredProperty == null)\n{\n    throw new InvalidOperationException(\"RequiredProperty must be set before this operation.\");\n}\nobj.DoOperation();","typeGuard":null,"tryCatchPattern":"try\n{\n    obj.DoOperation();\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"cannot be null\"))\n{\n    // log and guide the user to set required properties\n    throw;\n}","preventionTips":["Set all required properties before invoking operations that depend on them.","Use builder or init patterns that enforce required-property assignment at construction.","Add a Validate() method on your objects that checks state before use."],"tags":["validation","invalid-operation","state","property","verify"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}