473,588 Members | 2,527 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Properties.Sett ings NameValueCollec tion doesn't work?

For some unknown reason (user error?), I cannot get a NameValueCollec tion to
persist in the app.config file.

Unlike other settings, I cannot get the String Collection Editor GUI to
allow my to add/edit any values for a setting with type NameValueCollec tion.

Nor can I get a NameValueCollec tion to persist to the User Settings via code
using a simple C# Console App...

Is this a user error or ?

Thanks,
Rick
Here's the code behind:

using System;
using System.Collecti ons.Generic;
using System.Text;
using System.Collecti ons.Specialized ;

namespace Play_With_Setti ngs
{
class Program
{
static void Main(string[] args)
{
Console.WriteLi ne("Starting... ");

if (Properties.Set tings.Default.M yNameValueColle ction == null)
{
Properties.Sett ings.Default.My NameValueCollec tion = new
NameValueCollec tion();
}

Console.WriteLi ne(Properties.S ettings.Default .MyUserSetting) ;

Console.WriteLi ne(Properties.S ettings.Default .MyNameValueCol lection.Count);

Properties.Sett ings.Default.My UserSetting = "Hello Saturn!";

Properties.Sett ings.Default.My NameValueCollec tion.Add("name1 ",
"value1");
Properties.Sett ings.Default.My NameValueCollec tion.Add("name2 ",
"value2");
Properties.Sett ings.Default.My NameValueCollec tion.Add("name3 ",
"value3");

Properties.Sett ings.Default.Sa ve();
Console.WriteLi ne(Properties.S ettings.Default .MyNameValueCol lection.Count);
Console.WriteLi ne(Properties.S ettings.Default .MyUserSetting) ;

}
}
}

And now the app.config

<?xml version="1.0" encoding="utf-8" ?>
<configuratio n>
<configSections >
<sectionGroup name="applicati onSettings"
type="System.Co nfiguration.App licationSetting sGroup, System, Version=2.0.0.0 ,
Culture=neutral , PublicKeyToken= b77a5c561934e08 9" >
<section name="Play_With _Settings.Prope rties.Settings"
type="System.Co nfiguration.Cli entSettingsSect ion, System, Version=2.0.0.0 ,
Culture=neutral , PublicKeyToken= b77a5c561934e08 9" requirePermissi on="false" />
</sectionGroup>
<sectionGroup name="userSetti ngs"
type="System.Co nfiguration.Use rSettingsGroup, System, Version=2.0.0.0 ,
Culture=neutral , PublicKeyToken= b77a5c561934e08 9" >
<section name="Play_With _Settings.Prope rties.Settings"
type="System.Co nfiguration.Cli entSettingsSect ion, System, Version=2.0.0.0 ,
Culture=neutral , PublicKeyToken= b77a5c561934e08 9"
allowExeDefinit ion="MachineToL ocalUser" requirePermissi on="false" />
</sectionGroup>
</configSections>
<applicationSet tings>
<Play_With_Sett ings.Properties .Settings>
<setting name="MyValue" serializeAs="St ring">
<value>Hello World</value>
</setting>
</Play_With_Setti ngs.Properties. Settings>
</applicationSett ings>
<userSettings >
<Play_With_Sett ings.Properties .Settings>
<setting name="MyUserSet ting" serializeAs="St ring">
<value>Hello Mars</value>
</setting>
<setting name="MyTest" serializeAs="Xm l">
<value>
<ArrayOfStrin g
xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http ://www.w3.org/2001/XMLSchema">
<string>x=y</string>
<string>1=2</string>
<string>a=b</string>
</ArrayOfString>
</value>
</setting>
</Play_With_Setti ngs.Properties. Settings>
</userSettings>
</configuration>
Dec 15 '06 #1
0 2826

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
14716
by: davidw | last post by:
I always use NameValueCollection. But I read an article says the only differece between Hashtable and NameValueCollection is that NameValueCollection could accept more than one value with same key? I am not quite understand this. And I think NameValueCollection's Set is a nice method. If I use HashTable, how can I update a item in it? Do I have to check if it exists, and remove and add it again? Thanks.
4
2045
by: Steve Long | last post by:
Can anybody help me out with a code sample or other info on how to implement SyncRoot on a NameValueCollection? Or, is there another .NET class that does this for me with the same functionality as a NameValueCollection? Basically, I need mulitple value for any given key and I need to try and make sure it's tread safe. I can derive from it but it doesn't implement the SyncRoot member of the NameObjectCollectionBase. Thanks in advance...
4
4037
by: Hardy Wang | last post by:
Hi, I have a NameValueCollection, is it possible to bind this object to a two-column DataGrid? How to match columns? Thanks! -- WWW: http://hardywang.1accesshost.com ICQ: 3359839 yours Hardy
0
1897
by: Parag Mahajan | last post by:
Hi, I am using the membership provider class, "System.Web.Security.ActiveDirectoryMembershipProvider". I am using Login Server control and attaching the already configured "ActiveDirectoryMembershipProvider" in the web.config file. But my restriction is that I do not want to give the "connectionUsername" and "connectionPassword" in the web.config file. I want to update this 2 attributes at runtime in the Login1_LoggingIn event handler, so...
2
3428
by: DaTurk | last post by:
I have three interfaces, lets call them General, Client, Server. public interface General { public Value{get;} } public interface Client : General {}
13
7131
by: Dave | last post by:
When using the properties designer to store application wide properties how do you get this to work across a project group containing an EXE and a collection of DLLs. I'm using C#.Net 2005. I noticed that the designer creates and app.config that gets copied to the output directory as a .exe.config or .dll.config. In this setup any Application Scope property that is in the .exe.config file can be read in from the file and used. My...
7
18208
by: Dom | last post by:
It seems I can't look at the Properties.Settings.Default.xxxx value in the immediate window while I'm in debug mode. If I try, I get the message: "'System.Windows.Forms.PropertyStore' does not contain a definition for 'Settings'" I can still Debug.Print the value in my code. What gives?
2
3614
by: Jan Eliasen | last post by:
Hi I am having some problems reading configuration values from a configuration file, using C# 2.0. I have programmed a Windows Service, and this part goes well - it runs nicely. Now, the Windows Service must call a Web Service every now and then. I have added the web reference, and made it dynamic, so I can change the
0
1706
by: =?Utf-8?B?RnV0cm9uaWNzIERldmVsb3Blcg==?= | last post by:
I am trying to store a collection of custom types in a Properties.Settings file which I will be updating at run time and saving on exit of the program. I understand how to use the Properties.Settings file in this way for normal types (ints, chars etc) but I am struggling to get it to work for my own types. The type I want to use in the Settings file is a custom implementation of the generic Dictionary class using a string and another...
0
7929
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7860
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
7984
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8223
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6634
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5398
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3847
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
1458
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1195
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.