Answer the question
In order to leave comments, you need to log in
How to process configuration file in C# DLL?
The task is to put some lines into the configuration file of the plugin implemented in the DLL. I’ll make a reservation right away that this is a plugin for someone else’s system and I don’t have access to the config because the sandbox for the plugin.
If the values are entered as defaults, then the query seems to Properties.Settings.Default.passwd
produce the desired result. However, if the values are unknown before compilation, we will get an error.
After a few hours of reading the internet, solution #1 was discovered:
private void ReadAllSettings()
private void ReadAllSettings()
{
System.Configuration.Configuration config = null;
string configPath = Path.GetFileName(Assembly.GetExecutingAssembly().Location);
ExeConfigurationFileMap map = new ExeConfigurationFileMap();
map.ExeConfigFilename = configPath;
Log(configPath);
try
{
config = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None);
}
catch (Exception ex)
{
Log(ex.Message);
}
if (config != null)
{
Log("NOT NULL");
Log(GetAppSetting(config, "passwd").Length.ToString());
}
}
An error occurred loading a configuration file: The parameter 'exePath' is invalid.
Parameter name: exePath
Answer the question
In order to leave comments, you need to log in
I have like this
dllConfig = ConfigurationManager.OpenExeConfiguration(this.GetType().Assembly.Location);
connection = dllConfig.ConnectionStrings.ConnectionStrings[1].ConnectionString;
OpenMappedExeConfiguration
should be the path to config here, not exe
OpenExeConfiguration here to exe
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question