Is it possible to load web-config from console application?
c#, configuration, console-application, web-applications
Solution
You can set APP_CONFIG_FILE by AppDomain.CurrentDomain.SetData(string name, Object data).
string webconfigPath = "whatever......../web.config");
string webconfigDir = Path.GetDirectoryName(configPath);
AppDomain.CurrentDomain.SetData("APPBASE", webconfigDir);
AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", webconfigPath);
It is easy and you will get same setting for console application (cron) and web application.
Problem
My question is quite simple. I have a third party library which assumes that it will is used in a web site (needs special configuration sections in web.config). I would like to use this library in a C# console application. It is possible? I have tried `WebConfigurationManager.OpenWebConfiguration();` as well as just copy everything into app.config but it does not work. The error I receive is a ConfigurationErrorsException stating that ` An error occurred creating the configuration section handler for ...: Could not load type 'Configuration.RenderingSection' from assembly 'System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. `