从主程序中的app.config .showing错误中读取时

时间:2014-01-03 13:30:47

标签: c#

当我从app.config中调用它时。在代码的下一部分显示错误

static void Main(string[] args)

   {

   string Sys = ConfigurationManager.AppSettings["appsettings"];

   string[] sys1 = Sys.Split(',');

  List<string> symbols = new List<string>();

      foreach (string item in sys1)

        {

      symbols.Add(item);

        }

}
string idExchangeId = ConfigurationManager.AppSettings["idExchangeId"];

        Logger.Write("########## Commodities Control Rate Puller Program starting up ########## ");

        session = new RatePullerSession(hostname, 
                                            port, 
                                            username, 
                                            password, 
                                            idExchangeId, 
                                            symbols, 
                                            userModeOutputTokens);
        session.Initialize();

        session.Logon();
        session.SubscribeSymbols();            
        session.querySubscribedSymbols();
        session.ListenStreamingUpdates();
    }
}
}

1 个答案:

答案 0 :(得分:0)

看起来您正在尝试检索Configuration.AppSettings中保留的所有值。为此,请尝试使用ConfigurationManager.Appsettings.AllKeys,然后执行以下操作:

        var settings = ConfigurationManager.AppSettings.Keys;

        foreach (string setting in settings)
        {
            symbols.Add(ConfigurationManager.AppSettings[setting]);
        }