dotnet/wpf · error · InvalidOperationException
SR.AdornedElementNotFound
Error message
SR.AdornedElementNotFound
What it means
AdornerLayer.Update(element) throws InvalidOperationException(SR.AdornedElementNotFound) when the given element is not a key in the layer's ElementMap — i.e. this AdornerLayer has no adorners registered for that element. The method exists to force a re-measure/invalidate of all adorners on an element and requires the element to already be adorned.
Solutions
- Check AdornerLayer.GetAdorners(element) != null before calling Update.
- Re-acquire the layer via AdornerLayer.GetAdornerLayer(element) immediately before the call instead of using a cached reference.
- Only call Update on elements you previously called GetAdornerLayer(...).Add(adorner) for on that same layer instance.
- Wrap in try/catch for InvalidOperationException when the element's adornment state is inherently racy.
Example fix
// before
adornerLayer.Update(myElement); // throws if not adorned
// after
if (AdornerLayer.GetAdorners(myElement) != null)
adornerLayer.Update(myElement); Defensive patterns
Strategy: validation
Validate before calling
bool canUpdate = AdornerLayer.GetAdorners(element) != null; // only call adornerLayer.Update(element) when canUpdate is true
Type guard
bool IsAdornedOn(this AdornerLayer layer, UIElement e) => AdornerLayer.GetAdorners(e) != null;
Try / catch
try { adornerLayer.Update(element); } catch (InvalidOperationException) { /* not adorned; re-acquire layer and re-add adorners */ } Prevention
- Re-fetch the layer via AdornerLayer.GetAdornerLayer(element) right before use
- Check GetAdorners before any Update/Clear/ZOrder operation
- Don't cache AdornerLayer references across template or window changes
When it happens
Trigger: Calling AdornerLayer.Update(uiElement) (public API) on an element that (a) was never adorned on this layer, (b) had its adorners removed, or (c) is adorned on a different AdornerLayer than the one retrieved (e.g. GetAdornerLayer returned a different decorator after a layout/visual-tree change).
Common situations: Calling Update after RemoveAllAdorners; caching an AdornerLayer reference across a template swap or window recreation; calling Update on an element whose adorner layer is a different decorator in a nested-AdornerDecorator layout.
Understand the failure class
Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.
Related errors
- SR.AdornerNotFound
- annotation component
- Microsoft.Windows.Controls.SR.Format(Microsoft.Windows.Contr…
- Microsoft.Windows.Controls.SR.Format(Microsoft.Windows.Contr…
- Microsoft.Windows.Controls.SR.Ribbon_ContextualTabHeadersSou…
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/a6d0e1f9d2d7f395.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/AdornerLayer.cs:235
}
}
}
UpdateAdorner(null);
}
/// <summary>
/// Update (layout and render) all adorners for the given element.
/// </summary>
/// <param name="element">element key for redraw</param>
public void Update(UIElement element)
{
ArgumentNullException.ThrowIfNull(element);
ArrayList adornerInfos = ElementMap[element] as ArrayList;
if (adornerInfos == null)
throw new InvalidOperationException(SR.AdornedElementNotFound);
int i = 0;
while (i < adornerInfos.Count)
{
InvalidateAdorner((AdornerInfo)adornerInfos[i++]);
}
UpdateAdorner(element);
}
/// <summary>
/// Return a collection of all adorners adorning the given element
/// </summary>
/// <param name="element">Element for which adorners are to be retrieved</param>
/// <returns>array of adorners on given element, or null if
/// no adorners exist</returns>
public Adorner[] GetAdorners(UIElement element)View on GitHub (pinned to 81131a70a4)