Accessing settings from a windows control library project  
Author Message
ULeas





PostPosted: Common Language Runtime, Accessing settings from a windows control library project Top

Here is my problem.
i'm using vs2005 to write application for framework 2.0.
consider a solution with a windows forms application project and a windows control library project. The problem i have is with this control library project.
in the control project i have added an application setting of type connectionString. the studio made everything ok: it created the settings.designer.cs file with the settings wrapper and the app.confing file with the xml representation of the project's settings. Next, in the code of the project i have used the following code to access the value of the setting:
string str = projectname.Properties.Settings.Default.ConnectionString;

projectname is the name of the project, and ConnectionString is the name of the setting in the settings file.

during runtime, the str only get's the default value of the string, and only in case ia have set the property "insert the default value in the code" of the setting in the settings editor. if i set the property to false, then the default value isnt' embedded in the project source and the str gets an empty string, even if the projectname.dll.confg file is in the same directory as the rpojectname.dll and the winapp.exe.
what is the problem here
thatnx in advance



.NET Development6  
 
 
nobugz





PostPosted: Common Language Runtime, Accessing settings from a windows control library project Top

The default, and one and only, SettingsProvider implementation that .NET supplies is LocalFileSettingsProvider. It will only read the configuration file for the application and cannot read one for an assembly. The IDE is blissfully unaware of this and lets you create one for your class library, one you'll never be able to read.

The only solution I've found is to manually merge the class library's configuration file's content into the application's by hand. Trying to force LocalFileSettingsProvider to read from anything else than the application's configuration file proved to be futile. Replacing LocalFileSettingsProvider turned out to be highly non-trivial.


 
 
ULeas





PostPosted: Common Language Runtime, Accessing settings from a windows control library project Top

Thanx, nobugs.
This is what I also have come to , but couldn't believe it :)

The mechanism they use to access the properties is very complicated and i would say far not elegant.. I have found out that the LocalFileSettingsProvider uses , in the end, the ConfigurationManager and all these Configuration facilities they have in the library. And it showed out, that it's THERE impossible to open the class library's config file, because is forms the file name automatically and takes the main assembly name instead of the library's. This is what i have found so far, but unfotrtunately have no time to search more.
To solve my problem i managed to write my own SettingsProvider, so far it works fine, except that it still bothers me a lot that i can not access the library's config.
Anyway, if the thread is not closed by the time i will have found something else, i will write here.