我有一个生成CSV报告的C#程序。 我没有源代码,但我用dotPeek反编译代码。
当我开始编程时,我有例外:
System.ArgumentException:没有为密钥提供应用程序配置 [radioopt.qosextractor.export.filter.atm_os_versions]
我有相同的exe文件和配置文件名称,我在参考文献中有System.Configuration
,它使用ConfigurationManager
:
private static void ReadAtmOsVersions()
{
string appSetting = ConfigurationManager.AppSettings["radioopt.qosextractor.export.filter.atm_os_versions"];
StringBuilder stringBuilder = new StringBuilder();
if (string.IsNullOrWhiteSpace(appSetting))
throw new ArgumentException("No app config provided for key radioopt.qosextractor.export.filter.atm_os_versions.");
string path = appSetting.Trim();
if (!File.Exists(path))
throw new ArgumentException("Could not open config file " + path + ".");
foreach (string readAllLine in File.ReadAllLines(path))
{
if (!string.IsNullOrWhiteSpace(readAllLine))
{
string str1 = readAllLine.Trim();
if (!str1.StartsWith("//") && !str1.StartsWith("#"))
{
if (str1.Contains("//"))
str1 = str1.Substring(0, str1.IndexOf("//"));
string str2 = str1.Trim();
if (str2.Length > 0)
{
if (stringBuilder.Length == 0)
stringBuilder.Append(" { ");
else
stringBuilder.Append(",");
stringBuilder.Append(" \r\n [Devices].[OSVersion].&[" + str2 + "]");
}
}
}
}
if (stringBuilder.Length > 0)
stringBuilder.Append(" \r\n } ");
QoSConstants.ConfigFilter_FormattedOsVersionList = stringBuilder.ToString();
}
配置文件:
<!-- Files are dumpped locally first. -->
<add key="radioopt.qosextractor.export.dir.local" value=".\\export\\"/>
<!-- If the .final key exists the result (zip file) is copied to the folder given in the .final key -->
<add key="radioopt.qosextractor.export.dir.final" value=".\\final"/>
<!-- Number of recent csv exports to be put into the zip file (default = 4) -->
<add key="radioopt.qosextractor.export.zip.filecount" value="4"/>
<!-- In case the zip file shall be password protected -->
<!-- <add key="radioopt.qosextractor.export.zip.pwd" value="123456" /> -->
<!-- Config file providing the whitelist of ATM OS versions -->
<add key="radioopt.qosextractor.export.filter.atm_os_versions" value="filter_atm_os_versions.txt"/>
<!-- Config file providing the whitelist of countries -->
<add key="radioopt.qosextractor.export.filter.countries" value="filter_countries.txt"/>