{"record":{"id":"a2328d6bdef9fda4","repo":"PrismLibrary/Prism","slug":"resources-regionviewexistsexception","errorCode":null,"errorMessage":"Resources.RegionViewExistsException","messagePattern":"Resources\\.RegionViewExistsException","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Wpf/Prism.Wpf/Navigation/Regions/Region.cs","lineNumber":396,"sourceCode":"            RequestNavigate(target, navigationCallback, null);\n        }\n\n        /// <summary>\n        /// Initiates navigation to the specified target.\n        /// </summary>\n        /// <param name=\"target\">The target.</param>\n        /// <param name=\"navigationCallback\">A callback to execute when the navigation request is completed.</param>\n        /// <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            }","sourceCodeStart":378,"sourceCodeEnd":414,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Wpf/Prism.Wpf/Navigation/Regions/Region.cs#L378-L414","documentation":"Region.InnerAdd throws InvalidOperationException with RegionViewExistsException when the exact view object instance is already present in the region's ItemMetadataCollection. Prism forbids adding the same view instance twice to a region.","triggerScenarios":"Calling region.Add(sameViewInstance) twice, or region.Add(view, name) where the view instance is already registered under a different name.","commonSituations":"Re-activating a view by calling Add again instead of Activate; navigation re-triggered on the same view instance; event handlers firing twice (double-click, repeated initialization).","solutions":["Check region.Views.Contains(view) before calling Add; if present, call region.Activate(view) instead.","Cache whether the view was already added (e.g. a bool flag or view.IsLoaded check).","If a fresh visual state is needed, create a new view instance rather than re-adding the old one."],"exampleFix":"// before\nregion.Add(myView); // throws on second call\n// after\nif (!region.Views.Contains(myView))\n    region.Add(myView);\nelse\n    region.Activate(myView);","handlingStrategy":"type-guard","validationCode":"if (region.Views.Contains(view))\n{\n    region.Activate(view);\n    return;\n}\nregion.Add(view);","typeGuard":null,"tryCatchPattern":"try\n{\n    region.Add(view);\n}\ncatch (InvalidOperationException)\n{\n    region.Activate(view); // already present\n}","preventionTips":["Always check region.Views.Contains before adding.","Use Activate/Deactivate for show/hide instead of re-adding.","Debounce navigation triggers that can fire twice."],"tags":["wpf","prism","region","duplicate","invalid-operation"],"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"}