Exception "Activation error occured while trying to get instance of type Object" occurs while calling RequestNavigate"

Topics: Prism v4 - WPF 4
Feb 7, 2014 at 12:23 PM

I have a Prism with MEF framework application. UI Composition is mentioned below

     Top Region     ->View (Load View with MenuControl)
     BottomRegion -> View (Load View from different Modules when user clicks MenuItem) 
                                      -> SubRegion (Each View has SubRegion) 
                                           (Load view inside SubRegion from the loaded Module)
For Navigation, I am using RequestNavigate function. When I call RequestNavigate function to navigation to a view without SubRegion it works fine. But when i navigate to view with SubRegion I get below exception
"Activation error occured while trying to get instance of type Object"
Feb 7, 2014 at 7:58 PM

Based on the exception message it seems there was an error when trying to create the view. It would be useful if you could provide us with more information like the inner exceptions, how you are registering the view for navigation, etc.
Also, do you have any view registered thought view discovery (RegisterViewWithRegion...) for the SubRegion?


Damian Cherubini
Feb 10, 2014 at 5:22 AM
Hi Damian,

InnerException is null.
Below is the snapshot of the code which throws Exception at RequestNavigate: -
_regionManager.RequestNavigate(RegionNames.BottomRegion, new Uri(ViewNames.ModuleAMainView, UriKind.Relative));
public void Initialize()

If I add the code as below, exception is not thrown:-
public void Initialize()
var regionManager = ServiceLocator.Current.GetInstance<IRegionManager>();
regionManager.RegisterViewWithRegion(RegionNames.BottomRegion, typeof(ModuleAMainView));

As per my knowledge, Registering the view with region using RegisterViewWithRegion() should not be required for calling RequestNavigate().
Feb 12, 2014 at 4:31 PM

The observation you made is correct. RequestNavigate() call properly registers the View into the Region if it was not previously added. However, the problem may remain on the View registration into the Container. When calling RequestNavigate(), the Region tries to resolve the View by using serviceLocator in order to add it to the Region on ExecuteNavigation() process:
protected virtual object CreateNewRegionItem(string candidateTargetContract)
            object newRegionItem;
                newRegionItem = this.serviceLocator.GetInstance<object>(candidateTargetContract);
Therefore, this would be the core of your problem. I reproduced the exception you mentioned after I copied your scenario and commented the [Export] attribute of the navigated View. In order to properly register the Views in the container, one way you could accomplish is by declaring the [Export] attribute right above the class declaration, as follows:
public partial class HelloWorldView : UserControl, INavigationAware
Notice that this issue would happen for both View structures, with and without SubRegions though.
If you keep encountering an issue we would appreciate if you could provide us a small sample so we can debug it and give better support.

I hope this helped you,

Gabriel Ostrowsky
Marked as answer by shardabhagwatkar on 2/21/2014 at 5:49 AM
Feb 21, 2014 at 12:53 PM
Hi Gabriel,

I change the Export attribute from
[Export(typeof(HelloWorldView))] -> [Export("HelloWorldView")]

and it worked.