I have an Web.Api application that uses functions from a different assembly. For this assembly I have created a .config file where I store some strings.
I am using t
I solved this by using the following code:
// The dllPath can't just use Assembly.GetExecutingAssembly().Location as ASP.NET doesn't copy the config to shadow copy path
var dllPath = new Uri(Assembly.GetExecutingAssembly().GetName().CodeBase).LocalPath;
var dllConfig = ConfigurationManager.OpenExeConfiguration(dllPath);
// Get the appSettings section
var appSettings = (AppSettingsSection) dllConfig.GetSection("appSettings");
return appSettings.Settings;
The key there is:
new Uri(Assembly.GetExecutingAssembly().GetName().CodeBase).LocalPath
I came up with that solution after reading Zhaph - Ben Duguid's answer here: https://stackoverflow.com/a/2434339/103778.
Now I'm able to pick up my DLL's configuration file that is in the bin
directory of my web app.
I have since written up a blog post discussing this further.