Upgrading from PRISM 4.1 to PRISM 5 -> "Region with the given name is already registered"

Jun 3, 2014 at 12:43 PM

I'm having problems with my application after upgrading from 4.1 to 5.0.

Code that worked with PRISM 4.1 is as follows:
            // Build query parameters
            NavigationParameters query = new NavigationParameters(); // UriQuery previously
            query.Add("createRegionManagerScope", "true");
            query.Add("title", TitleText);
            query.Add("dashboardID", DashboardID.ToString());

            // Navigate to DashboardTabView with a title for the Tab item
                new Uri("EDM_ContractWaterFlowExtensionTabView" + query.ToString(), UriKind.Relative),
                (result) =>
                    // Parameters for view
                    NavigationParameters viewParams = new NavigationParameters();
                    // Current control instance ID
                    viewParams.Add("ControlInstanceID", ControlInstance.Id.ToString());

                    // Get scoped region manager and use it to navigate to sub view
                    var myRegionManager = result.ExtractRegionManager();
                        new Uri("EDM_ContractWaterFlowSiteListView" + viewParams.ToString(), UriKind.Relative)
But after upgrading to 5.0 I get following exception when requesting navigation to view in a region that already has one view (tab). This TabRegion is TabControl (which at this point already has one view with TabContentRegion) and I try to create another Tab with scoped region manager when navigating to the view EDM_ContractWaterFlowExtensionTabView.

An exception of type 'Microsoft.Practices.Prism.Regions.UpdateRegionsException' occurred in Microsoft.Practices.Prism.Composition.dll but was not handled in user code

Additional information: An exception occurred while trying to create region objects.

InnerException: Region with the given name is already registered: TabContentRegion

Changes that I have done are only changing UriQuery to NavigationParameters.
So adding first tab (view) works but when adding second one I get the exception.

ViewModel of the view that I try to navigate to is as follows:
    [Export(typeof(EDM_ContractWaterFlowExtensionTabViewModel)), PartCreationPolicy(CreationPolicy.NonShared)]
    public class EDM_ContractWaterFlowExtensionTabViewModel : DashboardTabViewModelBase
    // ...
DashboardTabViewModelBase (NotificationObject changed to BindableBase):
    [Export(typeof(DashboardTabViewModelBase)), PartCreationPolicy(CreationPolicy.NonShared)]
    public abstract class DashboardTabViewModelBase : BindableBase, INavigationAware, IRegionManagerAware
    // ...

Jun 5, 2014 at 9:46 PM
Hi Kalle,

I believe the issue you are having is related to the scoped region manager and that the same is not being created so all the regions are being registered in the same region manager, causing the issue you are describing.

It seems you are using the approach described here and that might not work anymore in PRISM 5.

Could you please provide a small sample reproducing the issue so we can take a further look to it?

Jun 6, 2014 at 10:59 AM

Thanks for the reply. You are correct, I am using approach that you mentioned with RegionManagerAwareBehavior. I'm now proceeding with my development using older branch that is still using Prism 4.1 but it would be nice to be able to use 5.0 at some point. I try to come up with some sample that can be used to reproduce this issue. There seems to have one guy with similar problems asking help on that scoped region thread you mentioned so good to know that I'm not the only one with this problem.

IRegionNavigationService interface that is used in CustomRegionNavigationService in this approach has INavigateAsync interface that has method RequestNavigate and at least that one got new NavigationParameters parameter in 5.0 and I don't have correct implementation for it... although I'm not sure if that should be the problem because parameters can (to my knowledge) be also passed to the navigation request like before with older version (as part of the Uri).