PrismLibrary/Prism · error · InvalidOperationException
Resources.CannotChangeRegionNameException
Error message
Resources.CannotChangeRegionNameException
What it means
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.
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.
Example fix
// before
region.Name = "NewRegionName"; // throws if already named
// after
regionManager.Regions.Remove("OldRegionName");
var newRegion = new Region { Name = "NewRegionName" };
regionManager.Regions.Add(newRegion); Defensive patterns
Strategy: validation
Validate before calling
if (region.Name != null && region.Name != newName)
throw new InvalidOperationException("Region names cannot change after assignment.");
region.Name = newName; Try / catch
try
{
region.Name = newName;
}
catch (InvalidOperationException)
{
// recreate the region with the new name instead
} Prevention
- Treat Region.Name as immutable after creation.
- Assign the name exactly once at region construction/XAML declaration.
- Recreate regions instead of renaming them.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- Resources.RegionViewExistsException
- Resources.RegionNameCannotBeEmptyException
- Resources.StringCannotBeNullOrEmpty
- Resources.RegionViewNameExistsException
- Resources.ViewNotInRegionException
AI-assisted analysis of PrismLibrary/Prism@358118cd64 (2026-09-15).
Data as JSON: /api/errors/a3f7546b361bc9cd.
Report an issue: GitHub.
Appendix: source
Thrown at src/Wpf/Prism.Wpf/Navigation/Regions/Region.cs:77
_context = value;
OnPropertyChanged(nameof(Context));
}
}
}
/// <summary>
/// Gets the name of the region that uniquely identifies the region within a <see cref="IRegionManager"/>.
/// </summary>
/// <value>The name of the region.</value>
public string Name
{
get => _name;
set
{
if (_name != null && _name != value)
{
throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.CannotChangeRegionNameException, _name));
}
if (string.IsNullOrEmpty(value))
{
throw new ArgumentException(Resources.RegionNameCannotBeEmptyException);
}
_name = value;
OnPropertyChanged(nameof(Name));
}
}
/// <summary>
/// Gets a readonly view of the collection of views in the region.
/// </summary>
/// <value>An <see cref="IViewsCollection"/> of all the added views.</value>
public virtual IViewsCollection Views
{View on GitHub (pinned to 358118cd64)