System.Configuration.ConfigurationManager not available?

后端 未结 8 1258
南方客
南方客 2020-12-09 07:30

In a VS2005 C# project I have added a reference to System.configuration. In the object browser, I can see the System.Configuration.ConfigurationManager. In Intellisense Syst

相关标签:
8条回答
  • 2020-12-09 07:48
    1. Go to Manage NuGet Packages
    2. Browse System.Configuration
    3. Install the Package System.Configuration.ConfigurationManager.
    0 讨论(0)
  • 2020-12-09 07:48

    It's just a guess, but maybe you should check if your project is using at least .NET framework 2.0. ConfigurationManager class is availvable since .NET 2.0 as dfescribed here: link on msdn

    0 讨论(0)
  • 2020-12-09 07:50

    From the MSDN documentation -

    To use the ConfigurationManager class, your project must reference the System.Configuration assembly. By default, some project templates, like Console Application, do not reference this assembly so you must manually reference it.

    https://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager.aspx

    0 讨论(0)
  • 2020-12-09 07:53

    For anyone who switches back and forth between developing ASP.NET WebForms and WinForms, this tip may come in handy.

    If you are developing in a C# WinForms project, you will find that attempting to use a ConfigurationManager to get at your app.config settings will result in the following error:

    The name 'ConfigurationManager' does not exist in the current context

    Since this is included by default in ASP.NET projects, this may come as a surprise. Just simply right-click on the "References" node in your project and look on the ".NET" tab. Scroll down and you should find System.Configuration. Add this to your project and you should be up and running.

    Adding a Reference to System.Configuration

    Provided you have already added System.Configuration to the using section at the top of your code, you should now be able to use config settings (such as connection strings) with code such as the following:

    con.ConnectionString = ConfigurationManager.ConnectionStrings[sConnection].ConnectionString;
    
    0 讨论(0)
  • 2020-12-09 07:54

    I think you need to implicitly refer to System.Configuration assembly.

    0 讨论(0)
  • 2020-12-09 07:58

    Although the using System.Configuration; command is automatically generated in the using section, for some reason the actual reference is not set.

    Go into add reference, .Net tab, and choose System.Configuration.

    ConfigurationManager will now be resolved.

    If you go to the project where the exact same setup works just fine and look at the references, you will see a reference to System.Configuration.

    0 讨论(0)
提交回复
热议问题