HandyOrg/HandyControl · error · InvalidOperationException

The property must be null at this time.

Error message

The property {0} must be null at this time.

What it means

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.

Solutions

  1. Clear/reset the property (or dispose and recreate the object) before calling the API again.
  2. Ensure the lifecycle order: detach/dispose the previous state before re-initializing.
  3. Guard the call site: only invoke when the property is null (e.g. if (obj.Prop == null) obj.Initialize(...)).

Example fix

// before
window.Attach(newSource); // InvalidOperationException: The property Source must be null at this time.
// after
window.Detach();
window.Attach(newSource);
Defensive patterns

Strategy: type-guard

Validate before calling

if (obj.Source != null)
    obj.Detach(); // reset state before re-initializing

Type guard

static bool IsClean(T obj) => obj?.Source == null;

Try / catch

try { obj.Attach(source); }
catch (InvalidOperationException ex) when (ex.Message.Contains("must be null at this time")) { obj.Detach(); obj.Attach(source); }

Prevention

When it happens

Trigger: 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.

Common situations: Double initialization of a control/window object, forgetting to Detach/Dispose before re-attaching, reentrancy during shutdown, caching a stale reference.

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


AI-assisted analysis of HandyOrg/HandyControl@2c0875ebd6 (2026-09-14). Data as JSON: /api/errors/2bae1cc7fe6bbe7b. Report an issue: GitHub.

Appendix: source

Thrown at src/Shared/Microsoft.Windows.Shell/Standard/Verify.cs:102

    [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
            }));
        }
    }

    [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
    [DebuggerStepThrough]
    public static void IsTrue(bool statement, string name)
    {
        if (!statement)
        {
            throw new ArgumentException("", name);
        }
    }

    [DebuggerStepThrough]
    [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]

View on GitHub (pinned to 2c0875ebd6)