{"record":{"id":"a6d0e1f9d2d7f395","repo":"dotnet/wpf","slug":"sr-adornedelementnotfound","errorCode":null,"errorMessage":"SR.AdornedElementNotFound","messagePattern":"SR\\.AdornedElementNotFound","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/AdornerLayer.cs","lineNumber":235,"sourceCode":"                    }\n                }\n            }\n\n            UpdateAdorner(null);\n        }\n\n        /// <summary>\n        /// Update (layout and render) all adorners for the given element.  \n        /// </summary>\n        /// <param name=\"element\">element key for redraw</param>\n        public void Update(UIElement element)\n        {\n            ArgumentNullException.ThrowIfNull(element);\n\n            ArrayList adornerInfos = ElementMap[element] as ArrayList;\n\n            if (adornerInfos == null)\n                throw new InvalidOperationException(SR.AdornedElementNotFound);\n\n            int i = 0;\n\n            while (i < adornerInfos.Count)\n            {\n                InvalidateAdorner((AdornerInfo)adornerInfos[i++]);\n            }\n\n            UpdateAdorner(element);\n        }\n\n        /// <summary>\n        /// Return a collection of all adorners adorning the given element\n        /// </summary>\n        /// <param name=\"element\">Element for which adorners are to be retrieved</param>\n        /// <returns>array of adorners on given element, or null if\n        /// no adorners exist</returns>\n        public Adorner[] GetAdorners(UIElement element)","sourceCodeStart":217,"sourceCodeEnd":253,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/AdornerLayer.cs#L217-L253","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"// before\nadornerLayer.Update(myElement); // throws if not adorned\n// after\nif (AdornerLayer.GetAdorners(myElement) != null)\n    adornerLayer.Update(myElement);","handlingStrategy":"validation","validationCode":"bool canUpdate = AdornerLayer.GetAdorners(element) != null;\n// only call adornerLayer.Update(element) when canUpdate is true","typeGuard":"bool IsAdornedOn(this AdornerLayer layer, UIElement e) => AdornerLayer.GetAdorners(e) != null;","tryCatchPattern":"try { adornerLayer.Update(element); } catch (InvalidOperationException) { /* not adorned; re-acquire layer and re-add adorners */ }","preventionTips":["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"],"tags":["wpf","adorner","invalidoperation"],"backgroundTag":"entity-not-found","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}