Hi Nick,
Based on my understanding, you read AppSettings in a Windows Service
application but the NameValueCollection of the settings returns empty. The
same code works perfect in a WinForm desktop application. If I'm off base,
please feel free to let me know.
I performed a test based on your description but didn't reproduce the
problem on my side.
I follow the instructions in the following MSDN document to create a
Windows Service application:
http://msdn.microsoft.com/en-us/library/aa984464(VS.71).aspx
I add an Application Configuration File in the project and add an
appSettings in the app.config file:
<configuration>
<appSettings>
<add key="appsetting1" value="value1"/>
<add key="appsetting2" value="value2"/>
</appSettings>
...
</configuration >
In the override OnStart method, I add the following lines of code:
Protected Overrides Sub OnStart(ByVal args() As String)
' Add code here to start your service. This method should set things
' in motion so your service can do its work.
Dim config As Configuration =
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)
Dim col As KeyValueConfigurationCollection =
config.AppSettings.Settings
Dim valuestr As String
valuestr = col.Item("appsetting1").Value & " " &
col.Item("appsetting2").Value
EventLog1.WriteEntry("In OnStart:" & valuestr)
End Sub
Build and install the Windows Service application. When the service is
started, an entry is written to the MyNewLog "In OnStart:value1 value2".
Is there any difference between your code and mine?
Sincerely,
Linda Liu
Microsoft Online Community Support
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.