1

I want to read the key-value pair from AppSettings inside the configuration file but I couldn’t see my custom AppSettings. I guess the program doesn’t see my custom configuration file. Any recommendations on that? thanks! I don’t want to place my key-value pair in the settings file because of security issues.

I added System.Configuration as a reference and tried the code below as this answer suggests but it didn't work.

Working with Rhino 6.30.20288.16410 and .NET Framework 4.6.2

Config file:

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

Code:

    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 "";
    }
Tahirhan
  • 352
  • 1
  • 7
  • 15
  • I remember having the same problem. A long time ago. Could not solve it. Did you verify ‚exeConfigPath‘? – Goswin Rothenthal Jan 07 '21 at 16:43
  • Yes, ExecutingAssembly gives plug-in rhp file.I guess in order to read data from App.config file we need to copy the content of the plugin config file to Rhino's config file and it is not a feasible solution for me so I managed to solve this security issue by putting valuable data into plug-in's custom license system. – Tahirhan Jan 08 '21 at 08:51

0 Answers0