Click here to Skip to main content
15,887,676 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a standard WPF application which I am developing and running on Windows 10. I have used the Settings Designer to create a couple of settings, one user-scoped and one application-scoped.

The 'top-level' WPF project is called 'MyApp.WPF' and this is set as both the assembly name and default namespace. When I look in the MyApp.exe.config file, I find each setting has two entries, like this:

<applicationSettings>
    <MyApp.WPF.Properties.Settings>
        <setting name="SettingOne" serializeAs="String">
            <value>ABC</value>
        </setting>
    </MyApp.WPF.Properties.Settings>
    <MyApp.WPF>
        <setting name="SettingOne" serializeAs="String">
            <value>ABC</value>
        </setting>
    </MyApp.WPF>
</applicationSettings>

<userSettings>
    <MyApp.WPF.Properties.Settings>
        <setting name="SettingTwo" serializeAs="String">
            <value>DEF</value>
        </setting>
    </MyApp.WPF.Properties.Settings>
    <MyApp.WPF>
        <setting name="SettingTwo" serializeAs="String">
            <value>DEF</value>
        </setting>
    </MyApp.WPF>
</userSettings>


As far as I can tell, the second entry (the one with the shorter 'MyApp.WPF' namespace) seems to be entirely redundant. This is not a problem, but I would like to remove it if I can, or at the very least understand why it is there.

Has anyone encountered this?

What I have tried:

I have tried changing the user setting at runtime, and this creates the expected entry in the /%Username%/MyApp/.../user.config file, but this doesn't help me understand what is going on with the main MyApp.exe.config file in the application root directory.
Posted
Updated 7-May-17 0:08am
Comments
Maciej Los 30-Apr-17 6:04am    
Well, i'd try to copy settings file and rename it (eg.: MyApp.config_copy). Then i'd try to remove duplicated entries. Let me know, does it help?
Patrick Skelton 30-Apr-17 12:30pm    
Thanks for the reply. I have done something similar - deleting the file entirely. When the application recreates it during the build process, the entries are once more duplicated.
J. Calhoun 4-May-17 13:05pm    
Did you break point the function that you are using to create the settings file? I don't know what your code looks like, but it sounds like you are calling it multiple times on start up maybe due to some inheritance calling the constructor that creates these settings multiple times?
Patrick Skelton 4-May-17 14:46pm    
Thanks for the reply.

I'm not clear on where you suggest putting a breakpoint. The code is auto-generated. I simply create the settings using the Settings Designer. The rest is Microsoft magic (or it would be magic if I understood half of what it is doing).
J. Calhoun 4-May-17 16:04pm    
I overlooked the "Settings Designer" part, my apologies. However I do have one more question. When you say you created one application scope, and one user scope, are you using just the startup project designer? Is it possible that you have those settings in more than one project? I set up a project and set my startup project with the same settings you have shown and it creates properly, working on other ways to try and recreate your problem. Also, in the app.config file you should see only one set of settings, if you manually edited that and did it in the designer that could cause a duplicate. So far all I have been able to do is created one user and one application setting, no duplicates :/

1 solution

In the end, only the 'nuke' approach seemed to fix this.

I deleted the settings file completely, closed Visual Studio, deleted all \obj and \bin folders, and started again. This now produces single values in the MyApp.exe.config file.

I think the whole system may have become confused by the fact that I attempted to use my own folder and namespace for the settings files. MSDN does say that the settings must be either in the \Properties project folder or the root folder ( Application Settings ).
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900