35

I've got a reference to System.Configuration - and ConfigurationSettings is found no problem - but the type or namespace 'ConfigurationManager' could not be found!?

I've read around - and it looks like it should belong to the same namespace as the ConfigurationSettings class.

EDIT: Please take note - I've clearly said I have added a reference to System.Configuration. There's been 4 comments already about this.

S..
  • 5,511
  • 2
  • 36
  • 43
  • 2
    You need to add reference to `System.Configuration` – StuartLC Oct 04 '12 at 12:52
  • Version 3.5. I've added a reference - read the OP. –  Oct 04 '12 at 12:53
  • Please post the code where you get that warning. Perhaps it's a syntax problem. Also look in Object Explorer under System.Configuration to see if ConfigurationManager is there. – D Stanley Oct 04 '12 at 13:00

8 Answers8

48

ConfigurationManager is a part of the System.Configuration after .Net 2.0. Add a reference to the System.Configuration dll. Try using System.Configuration.ConfigurationManager.

Ashwin Chandran
  • 1,447
  • 14
  • 11
19

You need to use the System Configuration namespace, this must be included in two ways:

  1. Right click the project and choose add reference, browse "Assemblies" and tick the System.Configuration assembly.

  2. Include the namespace in code:

    using System.Configuration;

S..
  • 5,511
  • 2
  • 36
  • 43
  • View the properties of the reference you have added, get the location and try and browse to it. – S.. Jan 23 '14 at 12:15
  • 3
    using the "using System.Configuration" didn't work for me. However adding via the "right-click > add reference > assemblies > System.Configuration" solution worked for me. Thank you. – T3.0 Apr 30 '14 at 21:37
  • Thanks for actually including steps as to how one adds a reference. – Phillip Schulze Sep 08 '21 at 13:16
5

You need to add a reference the System.Configuration assembly. This namespace was split across a few assemblies.

BlakeH
  • 3,354
  • 2
  • 21
  • 31
5

You will need to add the System.Configuration reference under the Reference folder in your project. Only adding the system.configuration with the using statement in your class is not enough.

parker
  • 59
  • 1
  • 1
  • 4
    The author stated: `I've clearly said I have added a reference to System.Configuration`. Additionally, this question is more than two years old, please answer a more current question next time. – ByteHamster Mar 04 '15 at 22:10
4

I'm working in VisualStudio 2015, and ConfigurationManager is not present at System.Configuration namespace anymore.

I was just trying to read the App.config file...

Then I found a solution:

Get:

string str = MyProjectNamespace.Properties.Settings.Default["MySettingName"].ToString();

Set:

MyProjectNamespace.Properties.Settings.Default["MySettingName"]="myString";
MyProjectNamespace.Properties.Settings.Default.Save();
3

I am using VS 2017, I added 'using System.Configuration' directive and also follow the step to add a reference assembly to the project but IDE still complaint configuration manager does not exist, it turn out it is due to the .net core installed by Nuget just add a empty container. The package System.Configuration.Configurationmanager 4.5.0 need to be installed as well. Start Tools -> Nuget Package Manager -> Package Manager Console and type "Install-Package System.Configuration.ConfigurationManager -Version 4.5.0" and this resolve the problem. Refer below screenshot in Object Browser in VS2017

enter image description here

iamdave
  • 12,023
  • 3
  • 24
  • 53
Alan
  • 31
  • 2
0

For me, this problem was solved when I put the "BuildConnectionString" function in a class and added "Imports System.Configuration" at the top of the class page. I did as the Microsoft site itself says. https://learn.microsoft.com/en-us/dotnet/framework/data/adonet/connection-string-builders

Private Sub BuildConnectionString(ByVal dataSource As String, _
ByVal userName As String, ByVal userPassword As String)

' Retrieve the partial connection string named databaseConnection
' from the application's app.config or web.config file.
Dim settings As ConnectionStringSettings = _
   ConfigurationManager.ConnectionStrings("partialConnectString")

If Not settings Is Nothing Then
    ' Retrieve the partial connection string.
    Dim connectString As String = settings.ConnectionString
    Console.WriteLine("Original: {0}", connectString)

    ' Create a new SqlConnectionStringBuilder based on the
    ' partial connection string retrieved from the config file.
    Dim builder As New SqlConnectionStringBuilder(connectString)

    ' Supply the additional values.
    builder.DataSource = dataSource
    builder.UserID = userName
    builder.Password = userPassword

    Console.WriteLine("Modified: {0}", builder.ConnectionString)
End If
End Sub

The important point is to use the function in the class. When I did this the error failed to find the source.

zokaee hamid
  • 522
  • 5
  • 16
0

Summer 2021, Visual Studio 2019 (core application). I had copied in some code with

ConfigurationManager.AppeSettings["yadayada"];

Just click the light bulb icon on the line where the problem appear and choose to instal System.Configuration Package.

Thomas Koelle
  • 3,416
  • 2
  • 23
  • 44