0

i have problems in reading DLL application setting in c# Visual Studio 2010. I post a sample code of the get workarounded using reflection because with the ConfigurationManager fails.

private string LDAPDomain 
{  
    get
    {
        string strPath = System.Reflection.Assembly.GetExecutingAssembly().GetModules()[0].FullyQualifiedName;
        string val = GetValues(strPath, "LDAPDomain"); 
        return val;
    }
}


//strPath is path of the file.
//strKey is key to access

private string GetValues(string strPath, string strKey)
{
    System.Configuration.Configuration con = System.Configuration.ConfigurationManager.OpenExeConfiguration(strPath);
    string strValue = con.AppSettings.Settings[strKey].Value;

    return strValue;
 }
Furqan Safdar
  • 16,260
  • 13
  • 59
  • 93
Simone Spagna
  • 39
  • 1
  • 4

1 Answers1

2

If you are expecting the main project referencing the DLL to pick up the app settings it doesn't work like that. The ConfigurationManager will read the config for the executing assembly, you need to put all the necessary configuration into your app if you want to use this.

Alternatively you can manually read the contents of your DLL's app.config file - see this question for some example code.

Community
  • 1
  • 1
James
  • 80,725
  • 18
  • 167
  • 237