I have a web application and a console application that both reference the same class library. The class library needs to read a config file for some custom configuration info.
When running with the windows app, I use the following to define my Configuration:
Configuration appConfig = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
But, with the web app, I use this instead:
Configuration appConfig = WebConfigurationManager.OpenWebConfiguration("\\web.config");
I don't want two versions of the class library, is there a way for it to open the configuration file that will work the same in both instances? If I use the ConfigurationManager option with the web application, I get the following error:
Value does not fall within the expected range.
at this line:
CustomConfig customConfig = (CustomConfig)appConfig.GetSection("CustomConfig");
I'm using C# and .NET framework 2.0
When running with the windows app, I use the following to define my Configuration:
Configuration appConfig = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
But, with the web app, I use this instead:
Configuration appConfig = WebConfigurationManager.OpenWebConfiguration("\\web.config");
I don't want two versions of the class library, is there a way for it to open the configuration file that will work the same in both instances? If I use the ConfigurationManager option with the web application, I get the following error:
Value does not fall within the expected range.
at this line:
CustomConfig customConfig = (CustomConfig)appConfig.GetSection("CustomConfig");
I'm using C# and .NET framework 2.0