Discussion:
Configuration of Windows service
(too old to reply)
Olegus
2007-03-05 20:13:25 UTC
Permalink
I have Windows service MyService, that reads some settings from
MyService.exe.config file via
ConfigurationManager.AppSettings["Setting_Key_Name"]. I tried to write
small WinForm frontend app(called it Manager.exe) to manage settings
of MyService, but have problems with accessing MyService.exe.config
from Manager app. I am getting this error:

"System.Configuration.ConfigurationElement.this[System.Configuration.ConfigurationProperty]'
is inaccessible due to its protection level"

My Manager app has this code to open a service config and read values
from it:

// Open service configuration file
string exePath =
System.IO.Path.Combine(Environment.CurrentDirectory,
"MyService.exe.config");
// Map to the application configuration file.
ExeConfigurationFileMap configFile = new
ExeConfigurationFileMap();
configFile.ExeConfigFilename = exePath;
Configuration configServ =
ConfigurationManager.OpenMappedExeConfiguration(configFile,
ConfigurationUserLevel.None);
string value = configServ.AppSettings["CheckUpdateTimeout"];

I can read/write from/to Manager.exe.config but looks like it is
prohibited in .NET to work with another app's config files.
Is there a solution to my problem?

Thanks,
Olegus
sloan
2007-03-05 21:49:58 UTC
Permalink
See here:

http://www.eggheadcafe.com/forumpost.aspx?topicid=6&forumpostid=85647

This is an alternate method to pull info from (~any) config file.
Post by Olegus
I have Windows service MyService, that reads some settings from
MyService.exe.config file via
ConfigurationManager.AppSettings["Setting_Key_Name"]. I tried to write
small WinForm frontend app(called it Manager.exe) to manage settings
of MyService, but have problems with accessing MyService.exe.config
"System.Configuration.ConfigurationElement.this[System.Configuration.Configu
rationProperty]'
Post by Olegus
is inaccessible due to its protection level"
My Manager app has this code to open a service config and read values
// Open service configuration file
string exePath =
System.IO.Path.Combine(Environment.CurrentDirectory,
"MyService.exe.config");
// Map to the application configuration file.
ExeConfigurationFileMap configFile = new
ExeConfigurationFileMap();
configFile.ExeConfigFilename = exePath;
Configuration configServ =
ConfigurationManager.OpenMappedExeConfiguration(configFile,
ConfigurationUserLevel.None);
string value = configServ.AppSettings["CheckUpdateTimeout"];
I can read/write from/to Manager.exe.config but looks like it is
prohibited in .NET to work with another app's config files.
Is there a solution to my problem?
Thanks,
Olegus
Olegus
2007-03-05 22:09:01 UTC
Permalink
Thanks for your answer, Sloan.

I changed OpenMappedExeConfiguration to OpenExeConfiguration and it
works now. But I have a strong feeling that I use
OpenExeConfiguration before and it did not work. Hmmmm. Weird.
Post by sloan
http://www.eggheadcafe.com/forumpost.aspx?topicid=6&forumpostid=85647
This is an alternate method to pull info from (~any) config file.
Post by Olegus
MyService.exe.config file via
ConfigurationManager.AppSettings["Setting_Key_Name"]. I tried to write
small WinForm frontend app(called it Manager.exe) to manage settings
of MyService, but have problems with accessing MyService.exe.config
"System.Configuration.ConfigurationElement.this[System.Configuration.Configu
rationProperty]'
Post by Olegus
is inaccessible due to its protection level"
My Manager app has this code to open a service config and read values
// Open service configuration file
string exePath =
System.IO.Path.Combine(Environment.CurrentDirectory,
"MyService.exe.config");
// Map to the application configuration file.
ExeConfigurationFileMap configFile = new
ExeConfigurationFileMap();
configFile.ExeConfigFilename = exePath;
Configuration configServ =
ConfigurationManager.OpenMappedExeConfiguration(configFile,
ConfigurationUserLevel.None);
string value = configServ.AppSettings["CheckUpdateTimeout"];
I can read/write from/to Manager.exe.config but looks like it is
prohibited in .NET to work with another app's config files.
Is there a solution to my problem?
Thanks,
Olegus
Continue reading on narkive:
Loading...