Search code examples
wpfmvvmprism-4

'System.InvalidOperationException' occurred in Microsoft.Practices.Prism.dll, while navigate to request


I get 'System.InvalidOperationException' occurred in Microsoft.Practices.Prism.dll

while i perform request to navigate. I navigate to a popup region. as first time when i invoke the command, view is getting loaded. but as i close the popup view and come back again to invoke, i get the above exception

this.regionManager.RequestNavigate(RegionNames.SecondaryRegion, new Uri(ViewNames.VW_SEC_SEARCH_SERVICE, UriKind.Relative));

what possibly causing this issue?


Solution

  • found the issue, that is caused due view is still persistent in region even though i closed it. i manually removed the views in that region and re-added again. that solved the problem

    if (this.regionManager.Regions[RegionNames.SecondaryRegion] != null)
                    {
                        List<object> views = new List<object>(this.regionManager.Regions[RegionNames.SecondaryRegion].Views);
    
                        foreach (object view in views)
                        {
                            this.regionManager.Regions[RegionNames.SecondaryRegion].Remove(view);
                        }
                    }