App settings accross multiple assemblies?  
Author Message
sroughley





PostPosted: Common Language Runtime, App settings accross multiple assemblies? Top

Hi all,

In .NET 1.1 I was able to define application settings within the App/Web.config file that could be accessed from any assembly within the application from System.Configuration.ConfigurationSettings.AppSetting.Item("..."). How can I do this in .NET 2.0

Thanks in advance,

Stephen.



.NET Development2  
 
 
Brendan Grant





PostPosted: Common Language Runtime, App settings accross multiple assemblies? Top

It works much the same way... only in the 2.0 world ConfigurationSettings has been deprecated and ConfigurationManager is the preferred route... although both still work, using ConfigurationSettings will throw a warning at compile time.

If the old way isn’t working for you... how is it failing Do you have a reference to System.Configuration.dll as part of the assembly trying to read the AppSettings



 
 
sroughley





PostPosted: Common Language Runtime, App settings accross multiple assemblies? Top

Thanks for your reply.

If I use the ConfigurationManager (I am referencing System.Configuration) from an assembly other than the .exe or web app, all that happens is the AppSettings collection returns Nothing when I try to reference a setting from the config file.

After a late night's hacking away I have now found that what I needed to do was to add an App.config file to each assembly (class library) as required and define the appropriate settings. I then override these settings in the config file of the exe or ASP application by supplying the following:
...

<configuration>
<configSections>
<section name="AssemblyName.My.MySettings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
...
<applicationSettings>
<
AssemblyName.My.MySettings>
<
setting name="SettingString" serializeAs="String">
<
value>SettingVal</value>
</
setting>
...

And this seems to do the trick.

Thanks for the help, though. It is much appreciated!

Stephen.