Override LoadContent not working

Apr 30, 2014 at 8:02 AM
Hi, I need some help.

I'll try to write my own ContentLoader, because my Modules in other Assemblys.
The other Assemblys not directly referenced in my Shell Project. They are loaded with Mef inside my ModuleDiscoveryService.
namespace Shell.Services
    //Not really using Mef here but inside my ModuleDiscoveryService and
    //it works.
    public class MefContentLoader : DefaultContentLoader
        private IModuleDiscoveryService _moduleService;
        private List<IModuleMetadata> _modules;

        private IView _activeView;
        private IModule _activeModule;

        // Constructor is fireing, getting the Metadata works fine.
        public MefContentLoader()
            //Here I get my ModuleDiscoveryservice
            //This service is just checking up my outputdirectory for
            //any ModuleAssemblys
            _moduleService = ServicePool

            //GetModulesMetadata return the Metadata.
            this.Modules = _moduleService.GetModulesMetadata();

        //Never fireing
        protected override object LoadContent(Uri uri)
            if (FirstFloor.ModernUI.ModernUIHelper.IsInDesignMode)
                return null;

            var module = (from m in this._modules
                           where m.ContentUri == uri.OriginalString
                           select m).FirstOrDefault();

            if (module == null)
                throw new ArgumentException(
                 "Sorry this uri was not found: " + uri);

            // unload old Module
            if (this.ActiveModule != null)

            //load new Module
            this.ActiveModule = _moduleService.ActivateModule(module);
            this.ActiveView = this.ActiveModule.GetView();

            return this.ActiveView;

        // Some properties...
        public List<IModuleMetadata> Modules
            get { return _modules; }
            set { _modules = value;}

        public IView ActiveView
            get { return _activeView; }
            set { _activeView = value;}

        public IModule ActiveModule
            get { return _activeModule; }
            set { _activeModule = value;}
I get a Navigation Failed, Rescource not found Exception.
Understandable, because ModernUI not using my override and try to find the given uri of a non referenced assembly.

Any help is appreciated. Thanks a lot.
Apr 30, 2014 at 8:50 AM
Ok i got it, stupid error.

I initialized the MefContentLoader inside the constructor of my application.
I've got to override the OnStartup method of my application. Now it works.
public App()
    // Bootstrap

   //MefContentLoader contentLoader = new MefContentLoader();
   //this.Resources.Add("MefContentLoader", contentLoader);

protected override void OnStartup(StartupEventArgs e)

     MefContentLoader contentLoader = new MefContentLoader();
     this.Resources.Add("MefContentLoader", contentLoader);
Marked as answer by Skymax086 on 4/30/2014 at 12:50 AM