.net 无法从App.Config中的AppSettings获取键值对

.net 无法从App.Config中的AppSettings获取键值对,.net,connection-string,app-config,rhino3d,.net,Connection String,App Config,Rhino3d,我想从配置文件中的AppSettings中读取键值对,但无法查看自定义AppSettings。我猜程序没有看到我的自定义配置文件。有什么建议吗?谢谢由于安全问题,我不想将密钥-值对放在设置文件中 我添加了System.Configuration作为参考,并按照建议尝试了下面的代码,但没有成功 合作 Rhino 6.30.20288.16410和 .NET Framework 4.6.2 配置文件: <?xml version="1.0" encoding="u

我想从配置文件中的AppSettings中读取键值对,但无法查看自定义AppSettings。我猜程序没有看到我的自定义配置文件。有什么建议吗?谢谢由于安全问题,我不想将密钥-值对放在设置文件中

我添加了System.Configuration作为参考,并按照建议尝试了下面的代码,但没有成功

合作 Rhino 6.30.20288.16410和 .NET Framework 4.6.2

配置文件:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="dbConnStr" value="MyConnectionString"/>
  </appSettings>
</configuration>

我记得我也有同样的问题。很久以前。无法解决它。您是否验证了“exeConfigPath”?是,ExecutiveGassembly提供插件rhp文件。我想为了从App.config文件中读取数据,我们需要将插件配置文件的内容复制到Rhino的配置文件中,这对我来说不是一个可行的解决方案,所以我设法通过将有价值的数据放入插件的自定义许可证系统来解决这个安全问题。我记得有过同样的解决方案问题很久以前。无法解决它。您是否验证了“exeConfigPath”?是,ExecutiveGassembly提供插件rhp文件。我想为了从App.config文件中读取数据,我们需要将插件配置文件的内容复制到Rhino的配置文件中,这对我来说不是一个可行的解决方案,所以我设法通过将有价值的数据放入插件的自定义许可证系统来解决这个安全问题。
    private static string GetAppSetting(Configuration config, string key)
    {
        KeyValueConfigurationElement element = config.AppSettings.Settings[key];
        if (element != null)
        {
            string value = element.Value;
            if (!string.IsNullOrEmpty(value))
                return value;
        }
        return string.Empty;
    }

    private static string GetConnStr(string key)
    {
        Configuration config = null;
        string exeConfigPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
        try
        {
            config = ConfigurationManager.OpenExeConfiguration(exeConfigPath);
        }
        catch (Exception ex)
        {
            //handle errror here.. means DLL has no sattelite configuration file.
        }

        if (config != null)
        {
            string myValue = GetAppSetting(config, key);
            return myValue;
        }
        return "";
    }