Julien
Julien

Reputation: 263

Application settings values are default when read from another project

I have 2 projects. I am trying to get some user-scoped application settings from project A and read them from project B. To do that I created the following class (in project A):

public class GeneralSettings
{
    public string strLogFilesPath {get; private set;}

    public GeneralSettings()
    {
        this.strLogFilesPath = GSN_PrestaBiz_UserUI_VS2013.Properties.Settings.Default.PathLogFiles;
    }
}

And I then instanciate the class from project B :

GSN_PrestaBiz_UserUI_VS2013.GeneralSettings ps = new GSN_PrestaBiz_UserUI_VS2013.GeneralSettings();

but for some reason I just get the default value of the type every time, in this case (string) it's "" and for booleans that I have in another similar class it's "false".

But I know those are not the values of the settings. I tried to instanciate that same class from Project A (the same project the settings belong to) and it worked, the values are correct and not just the default ones.

What am I doing wrong ?

Upvotes: 0

Views: 109

Answers (1)

toadflakz
toadflakz

Reputation: 7944

The correct term for "project" is actually assembly so I will use that when referring to "project".

The ConfigurationManager does not work the way you are trying to use it. The files are not hardcoded/locked to the particular assemblybut rather to the specific executable.config and user.config.

When retrieving settings from another assembly what the ConfigurationManager is really looking for is in the current execution context's user.config/exe.config file but under the namespace of the other assembly.

This is why when you look in one assembly's configuration using ConfigurationManager at runtime, the settings exist but in the other executable's runtime, they do not.

Upvotes: 1

Related Questions