Getting application settings in control libraries and other separately compiled stuff
I will admit that i'm not really on top of the class structure yet:-( That said
I guess that I understand that in a control library My.Settings refers to any settings that are established for the library. (Not sure how I'd use that:-)
So the question is how do I see the settings associated with the main running application in a control library?
What I want to do is have the controls initialize themselves and save themselves into the application's user settings.
(I know, I should bind control properties to the application settings but whenever I try to do this Beta 2 exits - no error just shuts down gracefull!)
Regards,
Al
Well I not only RTFM'd but finally understood what I was reading. Application bindings does the trick neatly.
I was thrown way off because databindings lets you start the motions of binding to My.Settings but then causes the IDE to gracefully exit as advertised in the original posting.
The question remains though of how to do it programmatically in a separately compiled assembly from the main program
Regards,
Al
Al,
If you are using the default settings provider, then class libraries read their settings from the app.exe.config associated with the executable that loads them.
Let's say you create a setting called "foo" in your class library. You'll notice that the project automatically creates an app.config file that contains the following section:
<
applicationSettings>
<ClassLibrary1.Settings>
<setting name="Foo" serializeAs="String">
<value>bar</value>
</setting>
</ClassLibrary1.Settings>
</applicationSettings>Note - the app.config file for the class library is not loaded or recognized by the runtime (we generate it for as a form of 'documentation'). The runtime loads all settings from a single config file associated with the exe, so to configurre your class library settings you just copy and paste <ClassLibrary1.Settings> into the <applicationSettings> of the app.config for the executable. Since the setting section names are fully qualified by the library namespace, the library can easily find its section in the app.config file and load it's values. You'll then need to declare a section handler for <ClassLibrar1.Settings> by copy/pasting section declaration. The result should look as follows:
<
sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="settingsexe.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<section name="settingsdll.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</sectionGroup>
Hope this helps,
Sean