dotnet/wpf · error · ArgumentNullException
ArgumentNullException: hitTestParameters
Error message
ArgumentNullException: hitTestParameters
What it means
TextFlow.HitTestCore (the PointHitTestParameters overload) throws ArgumentNullException when hitTestParameters is null. Precise hit testing needs the hit point carried in the parameters to test against the rendered Rect.
Solutions
- Always construct PointHitTestParameters with a valid Point before hit testing
- Prefer public HitTest APIs (UIElement.HitTest/VisualTreeHelper.HitTest) which build parameters for you
- Null-check parameters in test/interop harnesses before invoking HitTestCore
Example fix
// before var result = flow.HitTestCore(null); // after var result = flow.HitTestCore(new PointHitTestParameters(new Point(x, y)));
Defensive patterns
Strategy: validation
Validate before calling
if (hitTestParameters != null) { var r = flow.HitTestCore(hitTestParameters); } Type guard
bool hasHitPoint(PointHitTestParameters p) => p != null;
Try / catch
try { result = flow.HitTestCore(p); } catch (ArgumentNullException) { result = null; } Prevention
- Use public HitTest entry points which construct parameters automatically
- Always build PointHitTestParameters from a real hit Point
- Null-check parameters in custom hit-test harnesses and tests
When it happens
Trigger: Calling HitTestCore(new PointHitTestParameters(...)) with null, or custom input/hit-test code invoking the protected method directly without constructing parameters.
Common situations: Custom hit-testing or input-simulation code paths; unit tests calling HitTestCore directly with null; interop layers that drop the parameters object.
Related errors
- ArgumentNullException: child
- ArgumentNullException(nameof(scriptName))
- ArgumentNullException(nameof(text))
- ArgumentNullException(paramName)
- block
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/76376944b655befe.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextFlow.cs:943
///<param name="child">Reference to a child UIElement that had AffectsParentMeasure/AffectsParentArrange property invalidated.</param>
protected internal sealed override void ParentLayoutInvalidated(UIElement child)
{
if (child == null)
{
throw new ArgumentNullException("child");
}
OnChildUIElementChanged(child);
}
/// <summary>
/// HitTestCore implements precise hit testing against render contents
/// </summary>
protected sealed override HitTestResult HitTestCore(PointHitTestParameters hitTestParameters)
{
if (hitTestParameters == null)
{
throw new ArgumentNullException("hitTestParameters");
}
Rect r = new Rect(new Point(), RenderSize);
if (r.Contains(hitTestParameters.HitPoint))
{
return new PointHitTestResult(this, hitTestParameters.HitPoint);
}
return null;
}
/// <summary>
/// Hit tests to the correct ContentElement
/// within the ContentHost that the mouse
/// is over
/// </summary>
/// <param name="point">View on GitHub (pinned to 81131a70a4)