Quantcast
Channel: SharpDevelop Community
Viewing all articles
Browse latest Browse all 1764

app.config file not generated correctly for empty setting values

$
0
0

Hi, I've just came across this bug: If you create a Settings.settings file and create a new setting value here, leaving default value blank (empty string), the value recieved by the application at runtime won't be empty at all: it will contain some whitespace. I've discovered that it's caused by a incorrectly generated app.config file:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <configSections>
        <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
            <section name="Test.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
        </sectionGroup>
    </configSections>
    <userSettings>
        <Test.Properties.Settings>
            <setting name="empty" serializeAs="String"><!-- Should be <value></value> -->
                <value>
                </value>
            </setting>
        </Test.Properties.Settings>
    </userSettings>
</configuration>

Steps to reproduce:
1. Create a new Windows Forms project
2. Ensure there are no settings or app.config files
3. Use Designer to add a textBox to the form, call it "textBox1" and make it multiline
4. Add a Load event handler to the form and change form code to this:
using System;
using System.Windows.Forms;

namespace Test
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }
        
        void MainFormLoad(object sender, EventArgs e)
        {
            textBox1.Text = Properties.Settings.Default.empty;
        }
    }
}

5. Create a new settings file, call it "Settings.settings"
6. Create a new entry, call it "empty", set type to string and ensure that the value is blank (empty string)
7. Run the application and check the textBox content (it should be empty, but it won't be)

I use SharpDevelop version 4.3.1.9430-406354be. I hope I provided all the needed information...
(please tell me about any mistakes in my English, I'll try to avoid them next time :-))


Viewing all articles
Browse latest Browse all 1764

Trending Articles