Unity Configuration From Sub Directories

Oct 13, 2011 at 12:30 AM


In my application, we are loading up prism modules from a ModuleBin subfolder using the app.config file as follows:

ConfigurationModuleCatalog cmc = new ConfigurationModuleCatalog();

This folder is a sub folder to the exe directory (we used to be loading up using the method of pointing it to a directory, but we don't want to have to reference the modules and all dependent DLLs from the exe).

The modules load up fine this way.  When the module loads up, we coded it to try to register all of the types it will need with the container using a config file. 

          Assembly assembly = Assembly.GetExecutingAssembly();
            Uri uriPath = new Uri(assembly.CodeBase);
            string path = Path.Combine(Path.GetDirectoryName(uriPath.AbsolutePath), "ModuleUnityConfiguration.XML");
            ExeConfigurationFileMap configMap = new ExeConfigurationFileMap { ExeConfigFilename = path };
            System.Configuration.Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configMap, ConfigurationUserLevel.None);

            if (config != null)
                UnityConfigurationSection section = (UnityConfigurationSection)config.GetSection("unity");

This works until I get to section.Configure(coitainer); 

At this point, if all of the DLLs referenced by the module are not in the exe directoy one directory up, I get the exception:

"The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)"

Now, clearly it is looking in the EXE directory for the DLLs.  My question is, is it possible to get it to look in the subdirectory, or do I have to place all of my modules and their dependencies in the exe directory?


Any help is greatly appreciated,