dotnet/reactive · error · InvalidOperationException
Did not find
Error message
Did not find '{xpath}' What it means
GetRequiredNode is an XmlDocument extension that selects a single node via XPath and throws InvalidOperationException if SelectSingleNode returns null. It exists so tooling can fail fast when an expected element/attribute is missing from an XML document rather than leaking a NullReferenceException later.
Solutions
- Verify the XPath string against the actual document structure and fix typos/case
- Handle XML namespaces explicitly (add namespace manager or use local-name() in the XPath)
- Confirm the source document is the expected version/schema that contains the node
Example fix
// before
var node = doc.GetRequiredNode("/Project/PropertyGroup/TargetFramework");
// after
var node = doc.SelectSingleNode("/Project/PropertyGroup/TargetFramework");
if (node == null) { /* document lacks the element; handle or report clearly */ } Defensive patterns
Strategy: validation
Validate before calling
var node = document.SelectSingleNode(xpath);
if (node is null) { Console.WriteLine($"Document lacks node for xpath '{xpath}'"); return; } Type guard
bool hasNode = document.SelectSingleNode(xpath) is not null;
Try / catch
try { var n = doc.GetRequiredNode(xpath); }
catch (InvalidOperationException ex) when (ex.Message.StartsWith("Did not find")) { Console.Error.WriteLine($"XML missing expected node: {ex.Message}"); } Prevention
- Validate XPath expressions against a sample of the real document in tests
- Account for XML namespaces in your XPath (use local-name() or a namespace manager)
- Pin/verify the input document schema version before processing
When it happens
Trigger: Calling document.GetRequiredNode("/some/xpath") where no node matches the XPath — wrong path spelling, wrong namespace prefix, or the element genuinely absent from the document.
Common situations: Gauntlet build scripts expecting a project-file element (e.g. a property in a .csproj) that was renamed or removed; XML documents with default namespaces where the XPath lacks namespace handling.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- action
- action (Parameter 'action')
- action (Parameter 'action')
- action (Parameter 'action')
- action (Parameter 'action')
AI-assisted analysis of dotnet/reactive@94b5d5ab91 (2026-09-15).
Data as JSON: /api/errors/865931e6c34b806c.
Report an issue: GitHub.
Appendix: source
Thrown at Rx.NET/Test/Gauntlet/RxGauntlet.Common/Xml/XmlExtensions.cs:14
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT License.
// See the LICENSE file in the project root for more information.
using System.Xml;
namespace RxGauntlet.Xml;
public static class XmlExtensions
{
public static XmlNode GetRequiredNode(this XmlDocument document, string xpath)
{
return document.SelectSingleNode(xpath)
?? throw new InvalidOperationException($"Did not find '{xpath}'");
}
public static void SetAttribute(this XmlNode node, string attributeName, string attributeValue)
{
var attributes = node.Attributes!;
if (attributes[attributeName] is not XmlAttribute attribute)
{
attribute = node.OwnerDocument!.CreateAttribute(attributeName);
attributes.Append(attribute);
}
attribute.Value = attributeValue;
}
}
View on GitHub (pinned to 94b5d5ab91)