0

I have following app.config. I would like save into ConnectionString key value - my text from serialized xml.

Private Shared strcon As String = New AppSettingsReader().GetValue("ConnectionString", GetType(System.String)).ToString()

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <appSettings>
           <add key="ConnectionString" value=""/>  
      </appSettings>
        <system.diagnostics>
            <sources>
...

So far i got this code but i am receiving error: "Object reference not set to an instance of an object."

on the line: config.AppSettings.Settings("ConnectionString").Value = "myconn"

' Get the configuration file.
        Dim config As Configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)

        ' Update the setting.
        config.AppSettings.Settings("ConnectionString").Value = "myconn" 

        ' Save the configuration file.
        config.Save(ConfigurationSaveMode.Modified)

        ' Force a reload of the changed section.
        ConfigurationManager.RefreshSection("appSettings")
unknown
  • 75
  • 7
  • possible duplicate of [What is a NullReferenceException and how do I fix it?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – James Thorpe Feb 04 '15 at 12:29
  • Follow the examples/debugging help given in that duplicate to get past your current exception, then if you're still having problems, feel free to ask a new question. – James Thorpe Feb 04 '15 at 12:30

0 Answers0