{"record":{"id":"a3f7546b361bc9cd","repo":"PrismLibrary/Prism","slug":"resources-cannotchangeregionnameexception","errorCode":null,"errorMessage":"Resources.CannotChangeRegionNameException","messagePattern":"Resources\\.CannotChangeRegionNameException","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Wpf/Prism.Wpf/Navigation/Regions/Region.cs","lineNumber":77,"sourceCode":"                    _context = value;\n                    OnPropertyChanged(nameof(Context));\n                }\n            }\n        }\n\n        /// <summary>\n        /// Gets the name of the region that uniquely identifies the region within a <see cref=\"IRegionManager\"/>.\n        /// </summary>\n        /// <value>The name of the region.</value>\n        public string Name\n        {\n            get => _name;\n\n            set\n            {\n                if (_name != null && _name != value)\n                {\n                    throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.CannotChangeRegionNameException, _name));\n                }\n\n                if (string.IsNullOrEmpty(value))\n                {\n                    throw new ArgumentException(Resources.RegionNameCannotBeEmptyException);\n                }\n\n                _name = value;\n                OnPropertyChanged(nameof(Name));\n            }\n        }\n\n        /// <summary>\n        /// Gets a readonly view of the collection of views in the region.\n        /// </summary>\n        /// <value>An <see cref=\"IViewsCollection\"/> of all the added views.</value>\n        public virtual IViewsCollection Views\n        {","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Wpf/Prism.Wpf/Navigation/Regions/Region.cs#L59-L95","documentation":"Region.Name is immutable once set: the setter allows assignment only while _name is still null. If you assign a different non-null name to an already-initialized region, Prism throws InvalidOperationException with CannotChangeRegionNameException because region name identity is relied upon by RegionManager registration and navigation.","triggerScenarios":"Setting Region.Name (directly or via XAML RegionManager.RegionName) to a value different from the already-assigned name of a live region, e.g. renaming a region after the region has been registered with the RegionManager.","commonSituations":"Renaming a region in XAML while reusing a cached/custom region; programmatically reconfiguring regions created by a previous app state; copy-pasting a control template and editing RegionName at runtime instead of recreating the region.","solutions":["Remove the region (RegionManager.Regions.Remove) and recreate it with the new name instead of mutating Name.","Set the region name exactly once at creation time and never reassign it; treat Name as read-only after initialization.","If the region came from XAML, change the RegionName attribute in the view and let a fresh region be created, rather than setting Name in code."],"exampleFix":"// before\nregion.Name = \"NewRegionName\"; // throws if already named\n// after\nregionManager.Regions.Remove(\"OldRegionName\");\nvar newRegion = new Region { Name = \"NewRegionName\" };\nregionManager.Regions.Add(newRegion);","handlingStrategy":"validation","validationCode":"if (region.Name != null && region.Name != newName)\n    throw new InvalidOperationException(\"Region names cannot change after assignment.\");\nregion.Name = newName;","typeGuard":null,"tryCatchPattern":"try\n{\n    region.Name = newName;\n}\ncatch (InvalidOperationException)\n{\n    // recreate the region with the new name instead\n}","preventionTips":["Treat Region.Name as immutable after creation.","Assign the name exactly once at region construction/XAML declaration.","Recreate regions instead of renaming them."],"tags":["wpf","prism","region","invalid-operation","immutability"],"backgroundTag":"invalid-state-transition","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"}