Search code examples
c#settingsambiguity

Ambiguity between settings in C#


I've made an C# app with an GUI and some settings file for user settings. However, when I'm about to read the current values of the settings like MySettings.Default.SettingsName; it works perfectly for the first set of settings, say MyFirstSettings. For the second however, let's call it MySecondSettings, I get an error measure that says Ambiguity between My first Settings.Default and MySecondSettings.Default. I haven't been able to find any other way to access the settings but to use the .Default though.

Any tips would be really appreciated!

Axel


Solution

  • If you to have two settings files, it would generally work without any problems:

    The following works (and compiles) for me perfectly:

    Settings1.Default.Value1 = "11";
    Settings1.Default.Save();
    
    Settings2.Default.Value1 = "22";
    Settings2.Default.Save();
    

    So, the problem might occur if you created/copied the Settings2 file in some own and not really "fair" way outside of VisualStudio (for instance). (In that case both settings file might be refering still to the same "Settings1" class).


    The way I created Settings2 file is to drag-n-drop in solution explored (with Ctrl key pressed (copying)) and renamed it from "Copy of Settings1" to just "Settings2".

    Selecting "Add/New Items..." and selecting a new settings file works also greatly.

    EDIT:

    As the author of the question commented below:

    In the DAQSettings "folder" I found two instances of the Designer, one named Day Settings1.Designer and one just named Settings.Designer.

    ... explains what was wrong in there, as there was a duplication (duplicate naming) for certain classes/elements, so the way to clear the problem is a "manual involving".