473,320 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

config file problems

I keep getting a null reference when trying to access my config file
through my windows service, I have placed the xml config file in my
debug folder with my .exe, and my code is shown below.

//where I call the app.config file
f =
X10Unified.Senders.Firecracker.GetInstance(Int32.P arse(System.Configuration.ConfigurationManager.App Settings["COM_Port"]));

//the config file
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings"
type="System.Configuration.ApplicationSettingsGrou p, System,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="namespace.Properties.Settings"
type="System.Configuration.ClientSettingsSection, System,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
requirePermission="false" />
</sectionGroup>
</configSections>
<applicationSettings>
<namespace.Properties.Settings>
<setting name="namespace_Service_gLink"
serializeAs="String">
<value>url</value>
</setting>
<setting name="COM_Port" serializeAs="String">
<value>"3"</value>
</setting>
</namespace.Properties.Settings>
</applicationSettings>
</configuration>

Jul 24 '06 #1
3 3789
Cody,
ConfigurationManager.AppSettings is only for reading the standard
appSettings standalone section that looks like this:

<appSettings>
<add key="yourKey" value="yourValue" />
</appSettings>

You need to use one of the configurationSettings reader classes to read your
custom "applicationSettings" Section.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"co**@garcia-co.com" wrote:
I keep getting a null reference when trying to access my config file
through my windows service, I have placed the xml config file in my
debug folder with my .exe, and my code is shown below.

//where I call the app.config file
f =
X10Unified.Senders.Firecracker.GetInstance(Int32.P arse(System.Configuration.ConfigurationManager.App Settings["COM_Port"]));

//the config file
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings"
type="System.Configuration.ApplicationSettingsGrou p, System,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="namespace.Properties.Settings"
type="System.Configuration.ClientSettingsSection, System,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
requirePermission="false" />
</sectionGroup>
</configSections>
<applicationSettings>
<namespace.Properties.Settings>
<setting name="namespace_Service_gLink"
serializeAs="String">
<value>url</value>
</setting>
<setting name="COM_Port" serializeAs="String">
<value>"3"</value>
</setting>
</namespace.Properties.Settings>
</applicationSettings>
</configuration>

Jul 24 '06 #2
Peter,
I seem to be having some difficulties with this, what is the simplest
way to use a config file with a windows service? All i need it to do
is be able to contain an int or a string.

Peter wrote:
Cody,
ConfigurationManager.AppSettings is only for reading the standard
appSettings standalone section that looks like this:

<appSettings>
<add key="yourKey" value="yourValue" />
</appSettings>

You need to use one of the configurationSettings reader classes to read your
custom "applicationSettings" Section.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"co**@garcia-co.com" wrote:
I keep getting a null reference when trying to access my config file
through my windows service, I have placed the xml config file in my
debug folder with my .exe, and my code is shown below.

//where I call the app.config file
f =
X10Unified.Senders.Firecracker.GetInstance(Int32.P arse(System.Configuration.ConfigurationManager.App Settings["COM_Port"]));

//the config file
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings"
type="System.Configuration.ApplicationSettingsGrou p, System,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="namespace.Properties.Settings"
type="System.Configuration.ClientSettingsSection, System,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
requirePermission="false" />
</sectionGroup>
</configSections>
<applicationSettings>
<namespace.Properties.Settings>
<setting name="namespace_Service_gLink"
serializeAs="String">
<value>url</value>
</setting>
<setting name="COM_Port" serializeAs="String">
<value>"3"</value>
</setting>
</namespace.Properties.Settings>
</applicationSettings>
</configuration>
Jul 24 '06 #3
1) Add an "Application Configurate File" to your project. It will be named
"app.config" during development. After a build, it will automatically be
copied to the runtime folder with the name "yourappname.exe.config".
2) use an appSettings section as detailed in my first response above, and
access the items with ConfigurationManager.AppSettting["keyname"];
That's it, aside from remembering to convert string values to integers.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"co**@garcia-co.com" wrote:
Peter,
I seem to be having some difficulties with this, what is the simplest
way to use a config file with a windows service? All i need it to do
is be able to contain an int or a string.

Peter wrote:
Cody,
ConfigurationManager.AppSettings is only for reading the standard
appSettings standalone section that looks like this:

<appSettings>
<add key="yourKey" value="yourValue" />
</appSettings>

You need to use one of the configurationSettings reader classes to read your
custom "applicationSettings" Section.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"co**@garcia-co.com" wrote:
I keep getting a null reference when trying to access my config file
through my windows service, I have placed the xml config file in my
debug folder with my .exe, and my code is shown below.
>
//where I call the app.config file
f =
X10Unified.Senders.Firecracker.GetInstance(Int32.P arse(System.Configuration.ConfigurationManager.App Settings["COM_Port"]));
>
//the config file
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings"
type="System.Configuration.ApplicationSettingsGrou p, System,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="namespace.Properties.Settings"
type="System.Configuration.ClientSettingsSection, System,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
requirePermission="false" />
</sectionGroup>
</configSections>
<applicationSettings>
<namespace.Properties.Settings>
<setting name="namespace_Service_gLink"
serializeAs="String">
<value>url</value>
</setting>
<setting name="COM_Port" serializeAs="String">
<value>"3"</value>
</setting>
</namespace.Properties.Settings>
</applicationSettings>
</configuration>
>
>

Jul 24 '06 #4

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

Similar topics

3
by: Peter Blum | last post by:
I have built an assembly (dll) from which I expect third parties to subclass. As a result, when my assembly has a version change, it will cause any third party assembly based on it to break unless...
1
by: miannone | last post by:
I was hoping someone could help me out. I have created a WindowsService that runs periodically throughout the day using a timer. This windows service looks into a Microsoft SQL database and looks...
3
by: Craig | last post by:
I've developed an single sign on web application that we'd like to use with all the applications we're developing. The application's connection string is stored in web.config. I've gotten some...
2
by: bmcelhany | last post by:
Hi all, I have a solution with 4 projects: a class library, a windows app, a windows service, and an installer project. The class library handles all communication with the database and its...
3
by: baylor | last post by:
I'm having a weird bug and wondering if anyone has ever seen this before A Hello World GUI app. Create an app.config. When you build, Studio copies app.config to bin\debug\ and renames it to the...
6
by: Mikey_Doc | last post by:
Hi We are running cms 2002, Framework 1.0 with Visual studio 2002. We have just upgraded to Framework 1.1 and visual studio 2003. All of our database connection strings are stored within the...
3
by: Mads Brydegaard | last post by:
Hi, I have created a custom Config handler for reading a custom config section in my .config file(s) It works very well! I have placed a web.config in my root directory and then I use sub...
8
by: Robert | last post by:
I have what I think should be a pretty common scenario in a corporate environment. I have a web app and three environments on three servers: Development, QA and Production. We develop in...
2
by: Luke Dalessandro | last post by:
I have an application with the following layout /root/ /root/Default.aspx /root/web.config /root/child/ /root/child/web.config web.config has a custom configuration section "testSection"...
5
by: =?Utf-8?B?SmVycnkgQw==?= | last post by:
I need to access the web.config file in a class. I am now using the line: rootWebConfig1 = WebConfigurationManager.OpenWebConfiguration("~") to get a reference to the config file. The question...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.