dotnet/maui · error · InvalidOperationException
The property {0} must be null at this time.
Error message
The property {0} must be null at this time. What it means
Verify.PropertyIsNull<T> (where T : class) throws InvalidOperationException when the property value is NOT null. This is the inverse state guard — it asserts a property must be unset at this point. Used in lifecycle transitions where a non-null property means the object has already been configured and should not be reconfigured.
Source
Thrown at src/Compatibility/Core/src/WPF/Microsoft.Windows.Shell/Standard/Verify.cs:161
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
[DebuggerStepThrough]
public static void PropertyIsNotNull<T>(T obj, string name) where T : class
{
if (null == obj)
{
Assert.Fail();
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "The property {0} cannot be null at this time.", name));
}
}
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
[DebuggerStepThrough]
public static void PropertyIsNull<T>(T obj, string name) where T : class
{
if (null != obj)
{
Assert.Fail();
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "The property {0} must be null at this time.", name));
}
}
/// <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>
/// <param name="message">The message to include in the ArgumentException.</param>
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
[DebuggerStepThrough]
public static void IsTrue(bool statement, string name, string message = null)
{
if (!statement)
{
Assert.Fail();
throw new ArgumentException(message ?? "", name);
}View on GitHub (pinned to f377ff1c5e)
Solutions
- Reset the property to null before re-invoking the method that requires it unset.
- Guard against re-entry at the call site (if (_prop != null) return or throw).
- Restructure the lifecycle so the property is set exactly once.
Example fix
// before manager.Configure(); // already configured // after manager.Reset(); // clears the property to null manager.Configure();
Defensive patterns
Strategy: validation
Validate before calling
// Pre-check: property must be null before the operation
if (obj.SomeProperty != null)
{
throw new InvalidOperationException("SomeProperty must be null before reconfiguration. Call Reset() first.");
}
obj.Reconfigure(); Try / catch
try
{
obj.Reconfigure();
}
catch (InvalidOperationException ex) when (ex.Message.Contains("must be null"))
{
obj.Reset();
obj.Reconfigure();
} Prevention
- Reset state to null before re-invoking one-shot configuration methods.
- Guard against double-configuration at the call site.
- Use an IsConfigured flag instead of relying on null state for lifecycle control.
When it happens
Trigger: Calling a method guarded by Verify.PropertyIsNull(_prop, "Prop") when _prop has already been assigned. The guard fires because the operation expects the property to be cleared first.
Common situations: Double-configuration of an object (calling Configure twice); re-initialization without reset; a setter that should only fire once but is invoked again on a second binding pass.
Related errors
- The property {0} cannot be null at this time.
- The parameter must be null.
- The parameter cannot be either null or empty.
- The parameter cannot be either null or empty or consist only
- The parameter must not be the default value.
AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13).
Data as JSON: /api/errors/81c294570995605d.
Report an issue: GitHub.