PC Review


Reply
Thread Tools Rate Thread

config file problems

 
 
cody@garcia-co.com
Guest
Posts: n/a
 
      24th Jul 2006
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.Parse(System.Configuration.ConfigurationManager.AppSettings["COM_Port"]));

//the config file
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings"
type="System.Configuration.ApplicationSettingsGroup, 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>

 
Reply With Quote
 
 
 
 
=?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
Guest
Posts: n/a
 
      24th Jul 2006
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




"(E-Mail Removed)" 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.Parse(System.Configuration.ConfigurationManager.AppSettings["COM_Port"]));
>
> //the config file
> <?xml version="1.0" encoding="utf-8" ?>
> <configuration>
> <configSections>
> <sectionGroup name="applicationSettings"
> type="System.Configuration.ApplicationSettingsGroup, 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>
>
>

 
Reply With Quote
 
cody@garcia-co.com
Guest
Posts: n/a
 
      24th Jul 2006
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
>
>
>
>
> "(E-Mail Removed)" 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.Parse(System.Configuration.ConfigurationManager.AppSettings["COM_Port"]));
> >
> > //the config file
> > <?xml version="1.0" encoding="utf-8" ?>
> > <configuration>
> > <configSections>
> > <sectionGroup name="applicationSettings"
> > type="System.Configuration.ApplicationSettingsGroup, 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>
> >
> >


 
Reply With Quote
 
=?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
Guest
Posts: n/a
 
      24th Jul 2006
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




"(E-Mail Removed)" 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
> >
> >
> >
> >
> > "(E-Mail Removed)" 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.Parse(System.Configuration.ConfigurationManager.AppSettings["COM_Port"]));
> > >
> > > //the config file
> > > <?xml version="1.0" encoding="utf-8" ?>
> > > <configuration>
> > > <configSections>
> > > <sectionGroup name="applicationSettings"
> > > type="System.Configuration.ApplicationSettingsGroup, 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>
> > >
> > >

>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Web Config File Problems =?Utf-8?B?TWlrZSBNb29yZQ==?= Microsoft Dot NET 1 3rd Aug 2005 10:19 PM
Encrypting Config File...some problems though xanthviper@xanthviper.com Microsoft ASP .NET 0 29th Jul 2005 07:47 PM
Config File Problems in VS 2003 Lester Microsoft Dot NET Framework 1 3rd Dec 2003 06:10 PM
Paging File Config Problems Lerch Windows XP General 2 16th Sep 2003 03:08 PM
App.config file <bindingRedirect> problems Peter Blum Microsoft Dot NET 3 24th Jul 2003 11:28 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:33 AM.