HandyOrg/HandyControl · error · InvalidOperationException
The property cannot be null at this time.
Error message
The property {0} cannot be null at this time. What it means
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.
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.
Example fix
// before var hwnd = window.Hwnd; // InvalidOperationException: The property Hwnd cannot be null at this time. // after window.EnsureInitialized(); var hwnd = window.Hwnd;
Defensive patterns
Strategy: type-guard
Validate before calling
if (obj.RequiredProperty == null)
obj.Initialize(); // or skip usage until initialized Type guard
static bool IsReady(T obj) => obj?.RequiredProperty != null;
Try / catch
try { UseComponent(obj); }
catch (InvalidOperationException ex) when (ex.Message.Contains("cannot be null at this time")) { obj.Initialize(); UseComponent(obj); } Prevention
- 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.
When it happens
Trigger: 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).
Common situations: 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.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- The parameter must be null.
- The property must be null at this time.
- The parameter must not be the default value.
- message
- ExceptionStringTable.CannotHostTriggerActionMultipleTimesExc…
AI-assisted analysis of HandyOrg/HandyControl@2c0875ebd6 (2026-09-14).
Data as JSON: /api/errors/567a001fcdacbd34.
Report an issue: GitHub.
Appendix: source
Thrown at src/Shared/Microsoft.Windows.Shell/Standard/Verify.cs:89
}
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
[DebuggerStepThrough]
public static void IsNull<T>(T obj, string name) where T : class
{
if (obj != null)
{
throw new ArgumentException("The parameter must be null.", name);
}
}
[DebuggerStepThrough]
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
public static void PropertyIsNotNull<T>(T obj, string name) where T : class
{
if (obj == null)
{
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "The property {0} cannot be null at this time.", new object[]
{
name
}));
}
}
[DebuggerStepThrough]
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
public static void PropertyIsNull<T>(T obj, string name) where T : class
{
if (obj != null)
{
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "The property {0} must be null at this time.", new object[]
{
name
}));
}
}View on GitHub (pinned to 2c0875ebd6)