Czytanie sekcji konfiguracji

0

mam plik app.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="ApiParameters" type="System.Configuration.DictionarySectionHandler" />
  </configSections>
  <SmsSerwerApiParameters>
    <add key="login" value="testLogin"/>
    <add key="haslo" value="foobar"/>
  </SmsSerwerApiParameters>
</configuration>

próbując czytać to w ten sposób dostaję nulla.

public static Dictionary<string, string> GetConfig()
        {
            var c = (ConfigurationManager.GetSection("ApiParameters") as Hashtable)
                                                                                .Cast<DictionaryEntry>()
                                                                                .ToDictionary(n => n.Key.ToString(), n => n.Value.ToString());

            return c;

        }
0

Przede wszystkim nie używaj HashTable. Poza tym Twoja sekcja nazywa się SmsSerwerApiParameters a nie: ApiParameters

0
<section name="ApiParameters"

xD bicz plis :D

0

tak, wkleiłem coś nie tak. Mój XML jest taki ( spóbowałem też ubrać to w grupę )

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="ApiParameters" type="System.Configuration.DictionarySectionHandler" />
  </configSections>
  <ApiParameters>
    <add key="login" value="testLogin"/>
    <add key="haslo" value="foobar"/>
  <ApiParameters>
</configuration>

samo wywołanie GetSection() daje null

1 użytkowników online, w tym zalogowanych: 0, gości: 1