Having trouble understanding how to "override" CreateShell()

Topics: Prism v4 - Silverlight 4
Jan 30, 2011 at 4:38 AM

Can anyone give me a clue why this code does not seem to work? This is a portion of a Silverlight app

using System;
using System.Windows;
using Microsoft.Practices.Prism;
using Microsoft.Practices.Prism.Modularity;
using Microsoft.Practices.Prism.UnityExtensions;
using Microsoft.Practices.Prism.MefExtensions;

namespace MyDemoApplication
    public class MyBootstrapper :  UnityBootstrapper

      protected override DependencyObject CreateShell()
           System.Windows.DependencyObject shell = new Shell() as System.Windows.DependencyObject;
           Application.Current.RootVisual = shell;
           return (shell);

      protected override IModuleCatalog CreateModuleCatalog()

          var uri = new Uri("modulecatalog.xaml"UriKind.Relative);
          //var catalog = ModuleCatalog.CreateFromXaml(uri);
          return (Microsoft.Practices.Prism.Modularity.ModuleCatalog.CreateFromXaml(uri));

These are the two compiler errors I'm getting:
Error 7 'MyDemoApplication.MyBootstrapper.CreateShell()': return type must be 'System.Windows.DependencyObject' to match overridden member 'Microsoft.Practices.Prism.Bootstrapper.CreateShell()' C:\Users\Edward\Documents\Visual Studio 2010\Projects\MyDemoApplication\MyDemoApplication\MyBootstrapper.cs 16 43 MyDemoApplication
Error 8 Cannot implicitly convert type 'System.Windows.DependencyObject' to 'System.Windows.UIElement'. An explicit conversion exists (are you missing a cast?) C:\Users\Edward\Documents\Visual Studio 2010\Projects\MyDemoApplication\MyDemoApplication\MyBootstrapper.cs 19 45 MyDemoApplication
I can't seem to understand how to get past this point. Any suggestions would be greatly appreciated....

Jan 30, 2011 at 5:05 AM

I would do it like the "Silverlight only - Open Modularity With Unity QuickStart"


        protected override DependencyObject CreateShell()
            return ServiceLocator.Current.GetInstance<Shell>();

        protected override void InitializeShell()

            Application.Current.RootVisual = (UIElement)this.Shell;

Note that the Application.Current.RootVisual line belongs in the initialize override, not the create. 

The missing cast to UIElement as seen in the code here is the reason for your second error.  I'm not getting the first error, so I suspect once you fix that line it will work.


Jan 30, 2011 at 11:39 AM

Thank you for the reply and direction!