Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / April 2006

Tip: Looking for answers? Try searching our database.

App.config file

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
msnews.microsoft.com - 28 Apr 2006 04:06 GMT
I am having a heck of a time trying to figure out how to get a setting in a
referenced assembly/dll from the exe's app.config file.  In other words, I
have an assembly called AcmeApp.exe which contains an app.config file.  This
exe references a dll AcmeHelper.dll which I am trying to read a
configuration setting out of the app.config file but am unable to get it to
work properly.  I am using the
ConfigurationManager.AppSettings.Get("CustomSetting") to get the value from
the app.config (in C# .NET 2.0)   Does anyone have any input on what I am
doing wrong.  (FYI: my dll and exe have different namespaces)   I have
included what would seam logical to me for the app.config.

<?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="AcmeApp.Properties.Settings"
type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"
/>
           <section name="AcmeHelper.Properties.Settings"
type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"
/>
       </sectionGroup>
   </configSections>
   <applicationSettings>
       <AcmeApp.Properties.Settings>
           <setting name="Test_Val1" serializeAs="String">
               <value>AcmeApp_Title</value>
           </setting>
       </AcmeApp.Properties.Settings>
       <AcmeHelper.Properties.Settings>
           <setting name="CustomSetting" serializeAs="String">
               <value>My Favorite Custom Setting</value>
           </setting>
       </AcmeHelper.Properties.Settings>
   </applicationSettings>
</configuration>
FUnky - 28 Apr 2006 05:39 GMT
Try this:
AcmeHelper.Properties.Settings.Default.CustomSetting

FUnky

--------------------------------------------------------------------------------------------------------------------------------------
>I am having a heck of a time trying to figure out how to get a setting in a
>referenced assembly/dll from the exe's app.config file.  In other words, I
[quoted text clipped - 36 lines]
>    </applicationSettings>
> </configuration>
Techno_Dex - 28 Apr 2006 14:49 GMT
The Settings class that gets created, is embedded in the dll, which means it
gets hard coded at build time.  The idea behind a config file is that is can
be changed without having to rebuild assemblies every time.  This is not a
viable solution as each custom will ultimately have different settings and
require the flexibility to change the default values.

> Try this:
> AcmeHelper.Properties.Settings.Default.CustomSetting
[quoted text clipped - 42 lines]
>>    </applicationSettings>
>> </configuration>
FUnky - 28 Apr 2006 15:18 GMT
> The Settings class that gets created, is embedded in the dll, which means
> it gets hard coded at build time.  The idea behind a config file is that
> is can be changed without having to rebuild assemblies every time.  This
> is not a viable solution as each custom will ultimately have different
> settings and require the flexibility to change the default values.

App.config is meant to be read-only and it contains your project's default
settings. The question pertained to this particular file .. so the solution
was perfectly correct.
In case someone wishes to have user specific custom settings, VS 2005
provides excellent solution for the same. It stores the user specific
settings in a separate user.config file under the User\Local
Settings\Application Data folder. When you run the exe, it first looks into
the user.config file. If it gets the settings, OK, but if not, it looks into
the app.config file and picks up the default settings.
Techno_Dex - 28 Apr 2006 16:31 GMT
That is so very backwards, as the settings may be application wide per
client, not user specific within the client's company.  Say you have the
company's Name or a ServerName as a setting in the config file so it is
customized per client.  The user.config file doesn't get created until the
first time the application runs and tries to write a value to the user
config section.  This means they don't have the application customized until
the user launches the app for the first time not to mention the possiblity
that the app won't work without the required config info being set before
first launch.  Besides, the App.config file is meant to be read-only at
run-time, which this is not as the values are set the first time after
installation and used from then on.  Not to mention if you include user
scoped settings from the Properties->Settings form that  they are created in
the app.config file in a <userSettings> group.  Besides, if this were the
case, there would be absolutely no reason to use this file as opposed to
using a resource (.resx) file which does the same exact thing.  This is
still not a viable solution as the values are being read from the
Settings.settings file not the actual app.config file.  If this were the
case, then there would be no reason to even deploy the app.config file.

>> The Settings class that gets created, is embedded in the dll, which means
>> it gets hard coded at build time.  The idea behind a config file is that
[quoted text clipped - 11 lines]
> into the user.config file. If it gets the settings, OK, but if not, it
> looks into the app.config file and picks up the default settings.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.