{"record":{"id":"ed706a84708d2907","repo":"dotnet/maui","slug":"there-is-no-root-component-with-selector-selecto","errorCode":null,"errorMessage":"There is no root component with selector '{selector}'.","messagePattern":"There is no root component with selector '(.+?)'\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/BlazorWebView/src/WindowsForms/RootComponentCollectionExtensions.cs","lineNumber":46,"sourceCode":"\n\t\t/// <summary>\n\t\t/// Removes the component associated with the specified <paramref name=\"selector\"/> from the collection\n\t\t/// specified by <paramref name=\"components\" /> .\n\t\t/// </summary>\n\t\t/// <param name=\"components\">The collection from which the component associated with the selector should be removed.</param>\n\t\t/// <param name=\"selector\">The selector associated with the component to be removed.</param>\n\t\tpublic static void Remove(this RootComponentsCollection components, string selector)\n\t\t{\n\t\t\tfor (var i = 0; i < components.Count; i++)\n\t\t\t{\n\t\t\t\tif (components[i].Selector.Equals(selector, StringComparison.Ordinal))\n\t\t\t\t{\n\t\t\t\t\tcomponents.RemoveAt(i);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tthrow new ArgumentException($\"There is no root component with selector '{selector}'.\", nameof(selector));\n\t\t}\n\t}\n}\n","sourceCodeStart":28,"sourceCodeEnd":50,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/BlazorWebView/src/WindowsForms/RootComponentCollectionExtensions.cs#L28-L50","documentation":"The RootComponentsCollection.Remove(string selector) extension method iterates all root components and removes the one whose Selector matches (ordinal comparison). If no component in the collection has that exact selector, it throws ArgumentException. This prevents silent no-ops when removing a component that was never added or was already removed.","triggerScenarios":"Calling components.Remove(\"#my-component\") when no RootComponent with Selector \"#my-component\" exists in the RootComponentsCollection. This includes cases where the selector was misspelled, the component was already removed, or was never added.","commonSituations":"Removing a component that was already removed in a previous call; typo in the selector string; case sensitivity mismatch (comparison is StringComparison.Ordinal, so '#App' != '#app'); removing by a selector that was dynamically generated and no longer matches; cleanup code that runs multiple times.","solutions":["Check if the component exists before removing: if (components.Any(c => c.Selector == selector)) components.Remove(selector);","Maintain a reference to the RootComponent object and check before removing.","Verify the selector string exactly matches what was used when adding (including case, since comparison is ordinal).","Track removal state to avoid double-removal in cleanup paths."],"exampleFix":"// before\ncomponents.Remove(\"#my-component\"); // throws if not found\n// after\nif (components.Any(c => c.Selector.Equals(\"#my-component\", StringComparison.Ordinal)))\n{\n    components.Remove(\"#my-component\");\n}","handlingStrategy":"validation","validationCode":"// Check existence before removing\nvar existing = components.FirstOrDefault(c => c.Selector.Equals(selector, StringComparison.Ordinal));\nif (existing is null)\n{\n    // Selector not found; skip or log\n    return;\n}\ncomponents.Remove(selector);","typeGuard":"static bool HasRootComponent(RootComponentsCollection components, string selector)\n{\n    return components.Any(c => c.Selector.Equals(selector, StringComparison.Ordinal));\n}","tryCatchPattern":"try\n{\n    components.Remove(selector);\n}\ncatch (ArgumentException)\n{\n    // Component was already removed or never existed; safe to ignore during cleanup\n}","preventionTips":["Track added component selectors in a set and check membership before removing.","Use ordinal string comparison awareness when matching selectors (case-sensitive).","Avoid calling Remove in cleanup paths that may execute multiple times.","Consider removing by index or object reference if available."],"tags":["blazor","blazorwebview","winforms","rootcomponent","validation","collection"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}