C# 我的dll配置文件或为什么无法解析节。。?
我遇到了一个问题,无法解析文档标准配置 例如:C# 我的dll配置文件或为什么无法解析节。。?,c#,.net,configuration-files,C#,.net,Configuration Files,我遇到了一个问题,无法解析文档标准配置 例如: private string GetConfigKey(string param) { Configuration dllConfig = ConfigurationManager.OpenExeConfiguration(this.GetType().Assembly.Location); AppSettingsSection dllConfigAppSettings = (AppS
private string GetConfigKey(string param)
{
Configuration dllConfig = ConfigurationManager.OpenExeConfiguration(this.GetType().Assembly.Location);
AppSettingsSection dllConfigAppSettings = (AppSettingsSection)dllConfig.GetSection("appSettings");
return dllConfigAppSettings.Settings[param].Value;
}
因此,我以以下形式从文件中获取设置:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="host" value="mail.ololo.by"/>
</appSettings>
<configSections>
<section name="provideConfig" type="System.Configuration.DictionarySectionHandler"/>
<section name="provideMailStatus" type="System.Configuration.DictionarySectionHandler" />
</configSections>
<provideConfig>
<add key="post@gate.ololo.by" value="Mail Subject 1"/>
<add key="guga@gate.ololo.by" value="Mail Subject 2"/>
</provideConfig>
<provideMailStatus>
<add key="status1" value="send"/>
<add key="status2" value="draft"/>
<add key="status2" value="other"/>
</provideMailStatus>
</configuration>
但不幸的是,这是一个问题。我好像弄不明白。
MB,我走错方向了
p.S.Config文件不能命名为“app.Config”-只有项目dll名称应命名为可执行文件名和“.Config”。甚至这个可执行文件也使用这个dll文件。 例如:ConSoleApplication.exe使用MyLibrary.dll。然后,配置文件必须命名为ConSoleApplication.exe.config
如果您需要为配置文件读取其他名称,则应将配置文件命名为可执行文件名和“.config”。甚至这个可执行文件也使用这个dll文件。 例如:ConSoleApplication.exe使用MyLibrary.dll。然后,配置文件必须命名为ConSoleApplication.exe.config
如果您需要其他名称来读取配置文件谢谢大家,我已经解决了这个问题。 我可以判断是否有人会感兴趣
致以最良好的问候,yauhen。谢谢大家,我已经解决了这个问题。 我可以判断是否有人会感兴趣
致以最良好的问候,yauhen。我在块“部分”中遇到了相同的问题,我正在将一些配置写入文件中。我无法解析“.config”文件并在文件中获取struct my节。我无法获取字典键和值。这是我的普遍问题。为我配置文件名,我想,如果您对文件的访问没有问题,就没有特殊的角色扮演。可以使用XmlSerializer反序列化此文件。但在本例中,我建议您将其存储在单独的xml文件中。为什么?我对access文件没有任何问题。我在获取部分时也有同样的问题。我想,我必须创建“类”由ConfigurationSection继承,不是吗?我想你们需要我在块“部分”中也有同样的问题,我正在将一些配置获取到文件中。我无法解析“.config”文件并在文件中获取struct my节。我无法获取字典键和值。这是我的普遍问题。为我配置文件名,我想,如果您对文件的访问没有问题,就没有特殊的角色扮演。可以使用XmlSerializer反序列化此文件。但在本例中,我建议您将其存储在单独的xml文件中。为什么?我对access文件没有任何问题。我在获取节方面也有同样的问题。我想,我必须创建由ConfigurationSection继承的“类”,不是吗?我想您需要
Hashtable hashtable =
(Hashtable)ConfigurationManager.GetSection("provideConfig");
foreach (DictionaryEntry dictionaryEntry in hashtable)
{
Console.WriteLine(dictionaryEntry.Key+" "+dictionaryEntry.Value);
}