0

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 ?

1
  • 2
    the location/file saved to is based on a hash of values for the app running, so one app cannot get settings for another unless you save them manually to a fixed location you control. We like this otherwise saving settings from a DLL method would put them somewhere that the app itself could not get to. Mar 10, 2015 at 14:48

1 Answer 1

1

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.

3
  • I see. So what should I do, read directly from the user.config file ?
    – Julien
    Mar 10, 2015 at 14:50
  • You could. Or you could add the settings you require from the other assembly in the executable's app.config and user.config file under the appropriate namespace.
    – toadflakz
    Mar 10, 2015 at 14:52
  • Additional explanation of what toadflakz is saying can be found in the answer here: stackoverflow.com/questions/4817051/… Mar 10, 2015 at 15:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.