Our aim is to have Zero dependency from the client configuration files for WCF services. we are using ConfigurationChannelFactory() to create the channel and specify the ConfigSettings.
ConfigSettings is loaded using the following code
ConfigurationManager.OpenExeConfiguration(ConfigFilePath);
So we have to provide the ConfigFilePath here.
we have both windows and web clients.
we have used below approaches to find out the path
AppDomain.CurrentDomain.BaseDirectory + "bin\\" + executingAssembly.GetName().Name + ".dll"
- Web client : AppDomain.CurrentDomain.BaseDirectory gives root folder of the web applicaton so its works fine
- Windows client : AppDomain.CurrentDomain.BaseDirectory gives path upto Debug/Release folder so, its throws error
Assembly.GetExecutingAssembly().Location
- Web client : Assembly.GetExecutingAssembly().Location gives path to the ASP.Net temp. files , where we dont have the config files. So its throws an error.
- Windows client : Assembly.GetExecutingAssembly().Location gives the correct location, so its works fine.
In order to make it works in web clients, we have to add the following key in client's web.config files.
<hostingenvironment shadowcopybinassemblies="false">
but it adds a dependency to the clients.
Can you guys please help me to find the path without worrying about the clients?