FxCop and Prism Applications

Topics: Prism v2 - Silverlight 3
Aug 14, 2009 at 2:44 AM

I'm trying to enforce some code analysis rules against my Silverlight projects based on Prism.  I'm running into errors with regard to the Bootstrapper.

Specifically, I'm getthing the following errors when trying to test the bootstrapper,

Method 'CreateShell' in type 'Test.MyBootstrapper' from assembly 'Test', Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' does not have an implementation.

Is there an incompatability with FxCop that I'm not aware of?

Thanks

Rick

Aug 14, 2009 at 11:50 AM

Did you implement the method? Bootstrapper is derived from UnityBootstrapper, which is an abstract class, and the implementation of "CreateShell" is required.

Aug 14, 2009 at 3:26 PM
Here's the class that I'm using.
    public class MyBootstrapper : UnityBootstrapper
    {
        protected override DependencyObject CreateShell()
        {
            ShellView shell = Container.Resolve<IShellViewModel>().View as ShellView;
            Application.Current.RootVisual = shell;
            return shell;
        }

        protected override void ConfigureContainer()
        {
            base.ConfigureContainer();

            Container.RegisterType<IAuthenticationContext, AuthenticationContext>(new ContainerControlledLifetimeManager());
            Container.RegisterType<IAuthorizationContext, AuthorizationContext>(new ContainerControlledLifetimeManager());
            Container.RegisterType<ISessionContext, SessionContext>(new ContainerControlledLifetimeManager());

            Container.RegisterType<IShellModel, ShellModel>(new ContainerControlledLifetimeManager());
            Container.RegisterType<IShellViewModel, ShellViewModel>();
            Container.RegisterType<IShellView, ShellView>();

            Container.Resolve<ISessionContext>();
        }

        protected override IModuleCatalog GetModuleCatalog()
        {
            ModuleCatalog catalog = ModuleCatalog.CreateFromXaml(
                    new Uri("ModuleCatalog.xaml", UriKind.Relative));

            return catalog;
        }
    }
Aug 14, 2009 at 6:53 PM

Hi Rick,

I have just talked with a colleague of mine who has been developing an application using Prism, Silverlight 3 and FxCop for a long time now. He says he had no issues while developing so far and FxCop works correctly.

If blackjack’s suggestion was not accurate for your scenario, you could check if you are not missing any assembly references, or if anything of your environment is reproducing a bug Visual Studio might have (I am not aware of anything related to this, but surfing the Web might throw some answers).

Please let me know if this helps.

Damian Schenkelman
http://blogs.southworks.net/dschenkelman

Aug 14, 2009 at 6:56 PM

Thanks for looking into this.  The project builds just fine, so I'm going to reflect through FxCop and see where it's breaking and I'll see how it is trying to activeate the code.

Aug 14, 2009 at 9:40 PM

Seems that when our custom rules the problem is arising when we try to load the assemblies to compare types,

Assembly asm = Assembly.LoadFrom(type.DeclaringModule.Location);

This was causing the exception.  I removed the depnedence on this and use the FrameworkType to evaluate the TypeNodes,

if (type.IsAssignableTo(FrameworkTypes.Attribute))

Thanks again for looking into this.