separate config file path issue

Jan 31, 2010 at 1:59 PM

I have created a unity.config file & placed it in my website bin folder. I have used following code to configure the container.

var assembly = Assembly.GetExecutingAssembly();
Uri uriPath = new Uri(assembly.CodeBase);
string path = Path.Combine(Path.GetDirectoryName(uriPath.AbsolutePath.Replace("%20"," ")), "unity.config");
var map = new ExeConfigurationFileMap() { ExeConfigFilename = path };
var config = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None);
var section = (UnityConfigurationSection)config.GetSection("unity");
var container = new UnityContainer();
return container;

A typical thing happened in my code. The uriPath.AbsolutePath returns following path which is the location of my machine


Now if I go with this path, the config file didn't load but if I replace %20 with a space, it worked fine. I could not sort why it is behaving like this. If you look at my code, you can see I used Replace function to get rid of this problem.

Any idea.....

Jan 31, 2010 at 8:02 PM

My first question is: what does "didn't load" mean? Do you get an exception? An empty section? Null?

This is probably as issue with config in general rather than Unity specific. What is the value of your section variable? Do you get back null, or do you get the wrong data?