473,651 Members | 2,580 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

AppSettings Section Being Returned Empty

Hi there,

I have a Windows Service application that has a load of settings
defined, I can access these using My.Settings.

I would like to pass the NameValueCollec tion of the settings to another
class but unfortunately no matter what I try I get an empty colleciton back,
i.e.

System.Configur ation.Configura tionSettings.Ap pSettings
<Obsolete
System.Configur ation.Configura tionManager.App Settings

Now I know the settings are there, this code was working perfect as a
standard executable, but since I changed it to a Windows Service, it just
stopped working, any idea where my settings have gone and how I can get the
NameValueCollec tion?

Thanks in advance.

Nick.
Jun 27 '08 #1
6 5386
Hi Nick,

Based on my understanding, you read AppSettings in a Windows Service
application but the NameValueCollec tion 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/libr...64(VS.71).aspx

I add an Application Configuration File in the project and add an
appSettings in the app.config file:
<configuratio n>
<appSettings>
<add key="appsetting 1" value="value1"/>
<add key="appsetting 2" 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 =
ConfigurationMa nager.OpenExeCo nfiguration(Con figurationUserL evel.None)
Dim col As KeyValueConfigu rationCollectio n =
config.AppSetti ngs.Settings
Dim valuestr As String
valuestr = col.Item("appse tting1").Value & " " &
col.Item("appse tting2").Value
EventLog1.Write Entry("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:
ms****@microsof t.com.

=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.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/subscripti...t/default.aspx.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.
Jun 27 '08 #2
Hi Linda,

Indeed there are differences between your code and mine. I have added
my settings through the project menu and let the IDE which has not produced
a settings element that looks anything like yours... e.g.

<applicationSet tings>
<SomeApp.My.MyS ettings>
<setting name="Port" serializeAs="St ring">
<value>1001,100 2</value>
</setting>
<setting name="LogFilePa th" serializeAs="St ring">
<value>c:\logs\ </value>
</setting>
<setting name="EnableSou nds" serializeAs="St ring">
<value>True</value>
</setting>
</SomeApp.My.MySe ttings>
</applicationSett ings>

As I mentioned in my previous post, I can access the settings through
the My namespace. So are you suggesting that I need 2 lots of settings? I
would rather just stick with the settings the way I have them, but if that
is the only way then I shall create another settings section, any ideas?

Thanks for your time.

Nick.

"Linda Liu[MSFT]" <v-****@online.mic rosoft.comwrote in message
news:T4******** ******@TK2MSFTN GHUB02.phx.gbl. ..
Hi Nick,

Based on my understanding, you read AppSettings in a Windows Service
application but the NameValueCollec tion 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/libr...64(VS.71).aspx

I add an Application Configuration File in the project and add an
appSettings in the app.config file:
<configuratio n>
<appSettings>
<add key="appsetting 1" value="value1"/>
<add key="appsetting 2" 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 =
ConfigurationMa nager.OpenExeCo nfiguration(Con figurationUserL evel.None)
Dim col As KeyValueConfigu rationCollectio n =
config.AppSetti ngs.Settings
Dim valuestr As String
valuestr = col.Item("appse tting1").Value & " " &
col.Item("appse tting2").Value
EventLog1.Write Entry("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:
ms****@microsof t.com.

=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.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/subscripti...t/default.aspx.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no
rights.


Jun 27 '08 #3
Hi Nick,

Thank you for your quick response!

Since you add application-scoped settings in the Settings.settin gs under
the My Project folder, you cannot access these settings through
ConfigurationMa nager.AppSettin gs property.

In your scenario, the application-scoped settings are in a section named
"SomeApp.My.MyS ettings" under a section group named "applicationSet tings".
To get these settings using ConfigurationMa nager, we need to get the
section group first and then get the section. The following is a sample:

Dim config As Configuration =
ConfigurationMa nager.OpenExeCo nfiguration(Con figurationUserL evel.None)

' get the section group named "applicationSet tings"
Dim secGroup As ConfigurationSe ctionGroup =
config.SectionG roups("applicat ionSettings")

' get the section named "SomeApp.My.MyS ettings"
Dim applicationSec As ClientSettingsS ection =
CType(secGroup. Sections("SomeA pp.My.MySetting s"), ClientSettingsS ection)

' get the settings of the section
Dim applicationSett ingCol As SettingElementC ollection =
applicationSec. Settings

' enumerate the element in the settings
For Each element As SettingElement In applicationSett ingCol
Console.WriteLi ne(element.Name & " " & element.Value.V alueXml.Value)
Next

Hope this helps.
If you have any question, please feel free to let me know.

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:
ms****@microsof t.com.

This posting is provided "AS IS" with no warranties, and confers no rights.
Jun 27 '08 #4
Hi Nick,

How about the problem now? Have you had a chance to try my suggestion?

If you have any question, please feel free to let me know.

Thank you for using our MSDN Managed Newsgroup Support Service!

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:
ms****@microsof t.com.

This posting is provided "AS IS" with no warranties, and confers no rights.

Jun 27 '08 #5
Hi Linda,

That's excellent, thank you for your help, that has solved the problem.

Nick.

"Linda Liu[MSFT]" <v-****@online.mic rosoft.comwrote in message
news:gy******** ******@TK2MSFTN GHUB02.phx.gbl. ..
Hi Nick,

Thank you for your quick response!

Since you add application-scoped settings in the Settings.settin gs under
the My Project folder, you cannot access these settings through
ConfigurationMa nager.AppSettin gs property.

In your scenario, the application-scoped settings are in a section named
"SomeApp.My.MyS ettings" under a section group named "applicationSet tings".
To get these settings using ConfigurationMa nager, we need to get the
section group first and then get the section. The following is a sample:

Dim config As Configuration =
ConfigurationMa nager.OpenExeCo nfiguration(Con figurationUserL evel.None)

' get the section group named "applicationSet tings"
Dim secGroup As ConfigurationSe ctionGroup =
config.SectionG roups("applicat ionSettings")

' get the section named "SomeApp.My.MyS ettings"
Dim applicationSec As ClientSettingsS ection =
CType(secGroup. Sections("SomeA pp.My.MySetting s"), ClientSettingsS ection)

' get the settings of the section
Dim applicationSett ingCol As SettingElementC ollection =
applicationSec. Settings

' enumerate the element in the settings
For Each element As SettingElement In applicationSett ingCol
Console.WriteLi ne(element.Name & " " & element.Value.V alueXml.Value)
Next

Hope this helps.
If you have any question, please feel free to let me know.

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:
ms****@microsof t.com.

This posting is provided "AS IS" with no warranties, and confers no
rights.


Jun 27 '08 #6
Hi Nick,

Thank you for your feedback! I'm glad to hear that the problem is solved
now.

If you have any questions in the future, please don't hesitate to contact
us. It's always our pleasure to be of assistance!

Have a nice day!

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:
ms****@microsof t.com.

This posting is provided "AS IS" with no warranties, and confers no rights.

Jun 27 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
15483
by: hazz | last post by:
I have spent more time than I care to admit trying to track down a very subtle error. Here is my app's xx.exe.config file. <?xml version="1.0" encoding="utf-8" ?> <configuration> <appsettings> <add key="PasswordProvider" value="fudge" /> </appsettings>
3
4882
by: Celebrate | last post by:
My application works fine when I run it locally but when I transfer it to our NEW Windows 2003 Web Edition server, I get a strange error. I've isolated the problem to when I issue a ConfigurationSettings.AppSettings call. My guess is, there's a security setting that I'm missing on my Server but what?? I've spend hours trying to debug this; help on this would be greatly appreciated... Here's the error I get:
2
9595
by: Fuehner | last post by:
Everyone-- I installed the .NET 2.0 framework on a server that also has version 1.1 installed. A few of my applications override the "appSettings" section in the web.config with a custom config handler. This all worked fine prior to installing the 2.0 framework but, now I get the following error... Section or group name 'appSettings' is already defined. Updates to this may
1
2735
by: Jenny | last post by:
Hello, I read my applications App.Config file using ConfigurationSettings.AppSettings When I try to check it's last access write time using File.GetLastWriteTime and the refresh new data from App.Config using ConfigurationSettings.AppSettings
1
2184
by: Sergei Shelukhin | last post by:
Hi. Is is possible to divide appSetting in two, having some values stored in web.config itself and some in a section referenced in appSettings file="...." attribute?
1
5811
by: Ken | last post by:
I'm currently using 1.1. Is there any way using the value of a ConfigurationSettings.AppSettings as a key of ConfigurationSettings.AppSettings.Tosting( )]? for example in web.config <add key="company" value="Hyundai" /> <add key="Hyundai" value="sonata" />
5
1433
by: Osamede Zhang | last post by:
I just can't understand what appSettings means, how it work thanks for your read osamede
2
501
by: =?Utf-8?B?R29sZHdpbmQ=?= | last post by:
Hi, There is something fundamental which i donn't get it. I created a new Win Forms project in dotNet 2.0. I added Keys and Values to the settings. When I use ConfigurationManager.AppSettings, it returns empty collection?! I can get the values through the use of Properties.Settings - Strongly types.
1
1453
by: =?Utf-8?B?THVib21pcg==?= | last post by:
Hi, I have a custom settings in <appSettingssection in the web.config. I need to modify this section from the C# exe application (NOT asp.net) web.config: <appSettings> <add key="MyKeyName" value="MyValue"/> <appSettings/>
0
8275
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8576
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7296
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6157
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5609
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4143
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4281
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2696
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1585
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.