App.config einge Section schreiben/lesen



  • Hallo Leute,

    ich hab ein Problem:)

    ich habe eine Test WPF Projekt erstellt + Configurationdatei (App.config).
    Nun möchte ich eine eigene Section hinzufügen:

    Hier die Section:

    public class OnDemandServiceAddress : ConfigurationSection
    	{
    		public OnDemandServiceAddress()
    		{ }
    
    		[ConfigurationProperty("Address")]
    		public string Address
    		{
    			get { return (string)this["Address"]; }
    			set { this["Address"] = value; }
    		}
    	}
    

    Hier das anfügen:

    // Open App.Config of executable
    			var tmp = ConfigurationManager.GetSection("OnDemandServicesSettings");
    
    			if (tmp == null)
    			{
    				var onDemandInfo = new OnDemandServiceAddress()
    					{
    						Address = IPAddress.Loopback.ToString()
    					};
    
    				Configuration config = ConfigurationManager.OpenExeConfiguration(
    					ConfigurationUserLevel.None);
    
    				// with an updated one
    				config.Sections.Add("OnDemandServicesSettings", onDemandInfo);
    				// Write the new configuration data to the XML file
    				config.Save();
    			}
    

    Un es will einfach nich funktionieren!! Die Ausführung funktioniert fehlerlos, der ConfigurationsManager enhält auch nach anfügen die Section.
    ABER ES WIRD EINFACH NICHTS IN DIE APP.CONFIG GESCHRIEBEN 😡

    Ich versteh es nich, was mach ich falsch??


Anmelden zum Antworten