1

My question isn't related to the connection string which is the most popular. The other only help I could find with this is someone not using the reference.

What I'm trying to do: I have a string stored in the app.config file, which looks like:

<applicationSettings>
  <App_5.Properties.Settings>
    <setting name="Location_Name" serializeAs="String">
      <value>String I want</value>
    </setting>

My code to pull the string is:

string Loc_Name = ConfigurationManager.AppSettings["Location_Name"];

I have the reference added, and used. When I run the program my return is always null.

0

1 Answer 1

11

You are storing it in the wrong place in the app.config. For single name/value pairs use the appSettings. Then your retrieval code in the question will work.

<configuration>
  <appSettings>
    <add key="Location_Name" value="String I want" />
  </appSettings>
</configuration>

Code (repeated from question)

var value = ConfigurationManager.AppSettings["Location_Name"];
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.