{"record":{"id":"cd7fbd6294fec34d","repo":"PrismLibrary/Prism","slug":"resources-regionviewnameexistsexception","errorCode":null,"errorMessage":"Resources.RegionViewNameExistsException","messagePattern":"Resources\\.RegionViewNameExistsException","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Wpf/Prism.Wpf/Navigation/Regions/Region.cs","lineNumber":404,"sourceCode":"        /// <param name=\"navigationParameters\">The navigation parameters specific to the navigation request.</param>\n        public void RequestNavigate(Uri target, Action<NavigationResult> navigationCallback, INavigationParameters navigationParameters)\n        {\n            NavigationService.RequestNavigate(target, navigationCallback, navigationParameters);\n        }\n\n        private void InnerAdd(object view, string viewName, IRegionManager scopedRegionManager)\n        {\n            if (ItemMetadataCollection.FirstOrDefault(x => x.Item == view) != null)\n            {\n                throw new InvalidOperationException(Resources.RegionViewExistsException);\n            }\n\n            var itemMetadata = new ItemMetadata(view);\n            if (!string.IsNullOrEmpty(viewName))\n            {\n                if (ItemMetadataCollection.FirstOrDefault(x => x.Name == viewName) != null)\n                {\n                    throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, Resources.RegionViewNameExistsException, viewName));\n                }\n\n                itemMetadata.Name = viewName;\n            }\n\n#if !AVALONIA\n            if (view is DependencyObject dependencyObject)\n            {\n                Regions.RegionManager.SetRegionManager(dependencyObject, scopedRegionManager);\n            }\n#else\n            if (view is AvaloniaObject avaloniaObject)\n            {\n                Regions.RegionManager.SetRegionManager(avaloniaObject, scopedRegionManager);\n            }\n#endif\n\n            ItemMetadataCollection.Add(itemMetadata);","sourceCodeStart":386,"sourceCodeEnd":422,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Wpf/Prism.Wpf/Navigation/Regions/Region.cs#L386-L422","documentation":"Region.InnerAdd throws InvalidOperationException formatted with RegionViewNameExistsException when a different view with the same viewName already exists in ItemMetadataCollection. View names are unique keys within a region.","triggerScenarios":"Calling region.Add(viewB, \"sameName\") when another view instance was previously added with name \"sameName\", even though viewB itself is new.","commonSituations":"Generating view names from a counter/format string that doesn't advance; re-registering a named view after recreating the view instance; multiple VMs computing the same default name.","solutions":["Ensure view names are unique per region — e.g. include an id/counter: $\"ItemView_{id}\".","Check whether the name is already taken via region.GetView(name) != null before adding, and pick a new name or remove the old view.","If replacing is intended, call region.Remove(region.GetView(name)) first, then Add with the same name."],"exampleFix":"// before\nregion.Add(newView, \"Details\"); // 'Details' may already exist\n// after\nif (region.GetView(\"Details\") != null)\n    region.Remove(region.GetView(\"Details\"));\nregion.Add(newView, \"Details\");","handlingStrategy":"validation","validationCode":"if (region.GetView(viewName) != null)\n    region.Remove(region.GetView(viewName));\nregion.Add(newView, viewName);","typeGuard":null,"tryCatchPattern":"try\n{\n    region.Add(newView, viewName);\n}\ncatch (InvalidOperationException)\n{\n    // name already used: remove old view then retry, or use unique name\n}","preventionTips":["Generate unique view names (ids/counters) per region.","Check region.GetView(name) != null before registering a name.","Remove existing views explicitly when replace semantics are intended."],"tags":["wpf","prism","region","duplicate","naming"],"backgroundTag":"file-already-exists","analyzedSha":"358118cd640d9a22ff8cf21c8ad197fa038b7990","analyzedAt":"2026-09-15T15:00:31.079Z","contentChangedAt":"2026-09-15T15:00:31.079Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}