dotnet/wpf · error · InvalidOperationException
The property must be null at this time.
Error message
The property {name} must be null at this time. What it means
Verify.PropertyIsNull<T> is the inverse assertion for properties: it demands that the property currently be null and throws InvalidOperationException if a value is still present. It enforces lifecycle state — typically that a resource was released or not yet created.
Solutions
- Null out the property (after disposing) before re-running the guarded code path.
- Add proper Dispose/cleanup so the property is cleared on teardown.
- If re-initialization is legal, relax or remove this assertion and use an explicit state flag instead.
- Check the interpolated property name in the message to find the stale reference.
Example fix
// before Verify.PropertyIsNull(this.Handler, nameof(this.Handler)); // still set this.Handler = CreateHandler(); // after (this.Handler as IDisposable)?.Dispose(); this.Handler = null; Verify.PropertyIsNull(this.Handler, nameof(this.Handler)); this.Handler = CreateHandler();
Defensive patterns
Strategy: validation
Validate before calling
if (this.Handler != null)
throw new InvalidOperationException("Handler must be released before re-initialization");
Verify.PropertyIsNull(this.Handler, nameof(this.Handler)); Type guard
static bool IsCleared<T>(T prop) where T : class => prop is null;
Try / catch
try {
Verify.PropertyIsNull(this.Handler, nameof(this.Handler));
} catch (InvalidOperationException ex) {
(this.Handler as IDisposable)?.Dispose();
this.Handler = null;
} Prevention
- Make Dispose idempotent and always null out owned properties.
- Prevent double initialization with an initialized flag.
- Route all teardown through a single cleanup path.
When it happens
Trigger: Calling Verify.PropertyIsNull(obj, name) while the property still holds a reference — e.g. re-initializing or disposing a component that asserts a previous instance was cleared, but cleanup didn't null it.
Common situations: Double initialization of a singleton property; Dispose patterns where the field reset was removed; re-entering setup code after a partial failure.
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 property cannot be null at this time.
- CurrentFixedPageWriter uninitialized
- FixedPageReader
- SR.AnnotationServiceNotEnabled
- SR.ApplicationShuttingDown
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/0af727403a675f9c.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Standard/Verify.cs:147
throw new ArgumentException("The parameter must be null.", name);
}
}
[DebuggerStepThrough]
public static void PropertyIsNotNull<T>(T obj, string name) where T : class
{
if (null == obj)
{
throw new InvalidOperationException($"The property {name} cannot be null at this time.");
}
}
[DebuggerStepThrough]
public static void PropertyIsNull<T>(T obj, string name) where T : class
{
if (null != obj)
{
throw new InvalidOperationException($"The property {name} must be null at this time.");
}
}
/// <summary>
/// Verifies the specified statement is true. Throws an ArgumentException if it's not.
/// </summary>
/// <param name="statement">The statement to be verified as true.</param>
/// <param name="name">Name of the parameter to include in the ArgumentException.</param>
[DebuggerStepThrough]
public static void IsTrue(bool statement, string name)
{
if (!statement)
{
throw new ArgumentException("", name);
}
}
/// <summary>View on GitHub (pinned to 81131a70a4)