Loading modules on demand in partial trusted applications

Topics: Prism v2 - WPF 3.5
Jun 15, 2009 at 8:38 AM

Hi,

I develop a XBAP application, that should run in partial trusted mode (internet zone) using the CAL framework. And I have to load modules on demand.

The following code works fine when I start the application in full trusted mode:

    public partial class Bootstrapper : UnityBootstrapper
    {
        protected override IModuleCatalog GetModuleCatalog()
        {
            ModuleCatalog catalog = new ModuleCatalog();

            const string moduleAssemblyQualifiedName1 = "DeviceManager.DeviceManagerModule, DeviceManager, Version=1.0.0.0, Culture=neutral, PublicKeyToken=81447ee4612243af";
            catalog.AddModule("DeviceManager", moduleAssemblyQualifiedName1, InitializationMode.OnDemand);

            const string moduleAssemblyQualifiedName2 = "NodeManager.NodeManagerModule, NodeManager, Version=1.0.0.0, Culture=neutral, PublicKeyToken=81447ee4612243af";
            catalog.AddModule("NodeManager", moduleAssemblyQualifiedName2, InitializationMode.OnDemand);

            return catalog;
        }

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

        protected override DependencyObject CreateShell()
        {   
            ShellPresenter presenter = Container.Resolve<ShellPresenter>();
            ShellMainPage shell = presenter.View as ShellMainPage;

            Container.RegisterInstance<IShellView>("ShellView", shell);
  
            NavigationWindow parent = shell.Parent as NavigationWindow;
            parent.ShowsNavigationUI = false;

            RegionManager.SetRegionName(shell.contentRegion, RegionNames.ContentRegion);

            RegionManager.SetRegionName(shell.leftSideBarRegion, RegionNames.LeftSideBarRegion);

            RegionManager.SetRegionName(shell.rightSideBarRegion, RegionNames.RightSideBarRegion);
           
            return shell;
        }

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

           IModuleManager manager = Container.Resolve<IModuleManager>();

           manager.LoadModule("NodeManager");

           INodeManager nm = Container.Resolve<INodeManager>();   <== this call throws a SecurityException
           if (nm != null)
           {
               nm.Activate(null);
           }
        }
}
But when I start the application in partial trusted mode, it throws the following SecurityException: "Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed."
I already added the AllowPartiallyTrustedCallersAttribute to the CAL framework and strong named all assemblies!
Can anyone help me please??

  Thanks, Andreas

 

Jun 17, 2009 at 8:50 PM

Hi Andreas,

 

I do not know your exact scenario, but judging from the line that is throwing the exception, this issue could be related to Unity. The following article lists Unity’s v1.2 limitations when running in Partial Trust Environments:

·         Using Unity in Partial Trust Environments

 

You might also get some more information about this in the Unity Forums.

 

You should also take into account that since XBAPs are not in the scope of the Composite Application Guidance for WPF & SL, some particular things might not be fully functional.

 

Please let me know if this helps.

 

Damian Schenkelman

http://blogs.southworks.net/dschenkelman

Jun 22, 2009 at 11:56 AM

Hi Damion,

thank you very much for your answer, it helped me to solve the problem.

The problem was, that the access modifier of my ModuleController classes was not public!

Thanks a lot,

Andreas