At the top of my program I have the following :
using System.Configuration;
Within my code, I have the following:
int CompanyID = Convert.ToInt32(ConfigurationManager.AppSettings["CompanyId"]
.ToString());
I am getting the following error though :
The name 'ConfigurationManager' does not exist in the current context
I am not sure what I am missing.
To expand a bit, you will need to add a reference to
System.Configuration.dllto get this to work. It’s kind of misleading because theSystem.Configurationnamespace also exists inside the baseSystem.dll, and holds some far lesser used objects likeSettingsContext. As a result, it seems like it really ought to work, but it doesn’t. It is really confusing, and currently one of those obtuse gotchas in the .NET framework.Fortunately,
System.Configuration.dllis in the .NET base framework, so you only need to add a reference by right-clicking on theReferencesfolder in your project, clickingAdd Reference, and then findingSystem.Configurationunder the.NETtab.After it has been imported into your project, don’t forget to add
using System.Configurationto the top of the code file you intend to useConfigurationManagerin.