none
Why wont y .config file save? RRS feed

  • Question

  • I have a custom Config file section.

    If I create the section anew and populate it  [i.e.  set all appropriate properties, the file saves with no problem.

    When I then run the app again, and make changes to one or more of the properties, the ConfigFile.Save() method does nothing.   Yet when I access the properties of the Config file section,  the updated values are there.

    Am I missing anything?


    Brent Rogers I.S.P.

    Monday, November 25, 2013 8:47 PM

All replies

  • Hi Brent ,

    so for the custom config section you defined, you're currently programmtically reading and updating it (save to the config file), correct? Then, would you show us the code you use to access the custom config seciton values and save it back to config file? When saving changes to config file programmtically, we can use the Save method with ConfigurationSaveMode.Full to ensure all changes are saved. e.g.

    config.Save(ConfigurationSaveMode.Full);

    and here is a web article mentioned custom config section and loading/saving in code:

    #Custom Configuration Sections for Lazy Coders
    http://www.codeproject.com/Articles/32490/Custom-Configuration-Sections-for-Lazy-Coders


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Tuesday, November 26, 2013 2:45 AM
    Moderator
  • It is "custom" as my class makes use of the  [ConfigurationProperty("xxxxx")] attribute.

    Now I do have some inheritance.  The class that is originally saved is called "SSNCSISConfig".  The class that I actually create is called "AutoFill" -- which inherits from SSNCSISConfig.

    That being said this is how I create the elements.

    			AutoFill.AutoFillElement	AutoFill = null;
    			if (SSNConfig.Services["AutoFill"] is AutoFill.AutoFillElement)
    			{
    				AutoFill = (AutoFill.AutoFillElement)SSNConfig.Services["AutoFill"];
    			}
    			else if( SSNConfig.Services["AutoFill"] is SSNCService.ServiceConfigElement )
    			{
    				AutoFill = new AutoFill.AutoFillElement(SSNConfig.Services["AutoFill"]);
    				SSNConfig.Services.Remove("AutoFill");
    				SSNConfig.Services.Add( AutoFill );
    			}
    			else
    			{
    				AutoFill = new AutoFill.AutoFillElement("AutoFill");
    				SSNConfig.Services.Add( AutoFill );
    			}
    			if( !AutoFill.QueueReadComponent.ElementInformation.IsPresent )
    			{
    				AutoFill.QueueReadComponent = new SSNCService.ObjectConfigElement();
    			}
    			if (!AutoFill.DBConnection.ElementInformation.IsPresent)
    			{
    				AutoFill.DBConnection = new SSNCService.DBConfigElement();
    			}
    			AutoFill.Queue = @".\$private\$autofill";
    			AutoFill.QueueReadComponent.Assembly = "AutoFillAssembly";
    			AutoFill.QueueReadComponent.PublicKey = "1234567890ABCDEF";
    			AutoFill.QueueReadComponent.Version = new Version("1.2.3.4");
    			AutoFill.DBConnection.Driver = "{SQLServer}";
    			AutoFill.DBConnection.Server = "PCBRER";
    			AutoFill.DBConnection.DataBase = "ICS";
    			AutoFill.DBConnection.User = "DBUser";
    			AutoFill.DBConnection.PassWord = "DBPassword";
    			AutoFill.DefaultPrice = 101.00;

    This is how I update the data in the config file.

    					AutoFill.AutoFillElement	AutoFill = null;
    					if (SSNConfig.Services["AutoFill"] is AutoFill.AutoFillElement)
    					{
    						AutoFill = (AutoFill.AutoFillElement)SSNConfig.Services["AutoFill"];
    					}
    					else if( SSNConfig.Services["AutoFill"] is SSNCService.ServiceConfigElement )
    					{
    						AutoFill = new AutoFill.AutoFillElement(SSNConfig.Services["AutoFill"]);
    						SSNConfig.Services.Remove("AutoFill");
    						SSNConfig.Services.Add( AutoFill );
    					}
    					else
    					{
    						AutoFill = new AutoFill.AutoFillElement("AutoFill");
    						SSNConfig.Services.Add( AutoFill );
    					}
    //					if( !AutoFill.QueueReadComponent.ElementInformation.IsPresent )
    					{
    						AutoFill.QueueReadComponent = new SSNCService.ObjectConfigElement();
    					}
    					AutoFill.QueueReadComponent.Assembly	= moduleSelect1.AName;
    					AutoFill.QueueReadComponent.PublicKey	= moduleSelect1.PublicKey;
    					AutoFill.QueueReadComponent.Version		= moduleSelect1.Version;
    					AutoFill.QueueReadComponent.Module		= moduleSelect1.Module;
    					AutoFill.DefaultPrice = 102.00;

    The new values of the AutoFill section appear to beare reflect when I access the configuration object(s).  Yet when I call the Save() method on the "Configuration" object, nothing happens.

    I tried deleting and re-adding the entire  "SSNConfig" section, but I get the error that the Section already exists.


    Brent Rogers I.S.P.

    Tuesday, November 26, 2013 1:07 PM