ConfigurationSettings.AppSettings returns empty - can anyone help? (Urgent)

Posted on 2005-04-29
Last Modified: 2012-08-14

this is kind of an urgent requirement. Sorry if this is vague but this is all the information i have available as the other person is at a remote location and has only given me these details. He is trying to retieve some appsettings in the config file in VB.NET and is getting an error with these symptoms:

symptoms: ConfigurationSettings.AppSettings returns empty

This all the info i have so is anyone able to provide a either a soltuion (well done if you can) or point me in the right direction.

Thanks you any help
Question by:cbridle
    LVL 23

    Accepted Solution

    The web.config file should contain a section like this:

       <add key="ConfigKey1" value="SomeValue"/>

    I'm presuming you already have a list of keys defined as per my example above. If not, then this is your problem - you need to add them.
    If you do have these, then you need to specifically request the setting you want:
    Dim strConfigValue as string = ConfigurationSettings.AppSettings("ConfigKey1")  -- VB.NET

    I'm not 100% but the key you are looking for may be case-sensitive (i.e. "configKey1" might return blank)
    LVL 28

    Assisted Solution

    check this;en-us;Q313405&SD=MSDN

    If you are using Visual Studio .NET then the best way to create your config file is to add an Application
    Configuration item to your Project. ie. Right click your project, go to ADD>Add New Item..> Application
    Configuration File..
    This will create a App.Config file along side your files in the project.

    Create Console Application That Reads Content of Configuration File
    You can store application settings within the configuration file that is associated with the application.
    Configuration files are saved in XML format. The System.Configuration and
    the System.Collections.Specialized namespaces in the Microsoft .NET Framework include the necessary
    classes to retrieve information from a .NET application configuration file during run time.

    In Solution Explorer, click Show All Files .
    Right-click Bin , and then click Include in Project .
    Right-click the Bin folder, point to Add , and then click Add New Item .
    In the Add New Item dialog box, select the Application Configuration File template, click Open , and then
    add the App.config file to the project.

    NOTE : Application configuration files must reside in the same folder as the executable file that they are
    associated with. Because Visual Studio .NET places executable files in the Bin folder, you must also place
    the configuration file in the Bin folder.

    You must name the application configuration file according to the following format:
    ApplicationName . ApplicationType .config
    In Solution Explorer, right-click App.config , and then click Rename . Rename the App.config file
    ConfigurationFile.exe.config . The associated application can now locate this .config file.

    Configuration file

    <?xml version="1.0" encoding="utf-8" ?>
                <add key="Key0" value="0" />
                <add key="Key1" value="1" />
                <add key="Key2" value="2" />

    App (ConfigurationFile)

    Imports System.Configuration
    Imports System.Collections.Specialized

    Public Class Form1
        Inherits System.Windows.Forms.Form

    #Region " Windows Form Designer generated code "
    #End Region

        Dim sAttr As String

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            sAttr = ConfigurationSettings.AppSettings("Key0")
            MsgBox("The value of Key0: " & sAttr)

        End Sub

        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            Dim sAll As NameValueCollection
            Dim msg As String

            sAll = ConfigurationSettings.AppSettings()

            Dim s As String
            For Each s In sAll.AllKeys

                msg &= "Key: " & s & " Value: " & sAll(s) & vbCrLf

        End Sub
    End Class
    LVL 35

    Assisted Solution

    also make sure key and value are all lower-case and not "Key" or "Value"

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    Normally the drop down box control found in the .Net framework tools is able to select just one data and value at a time, which is displayed on the text area.   But what if you want to have multiple values to be selected in the drop down box? As …
    This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now