473,698 Members | 2,051 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Complex data types in User-scoped ApplicationSett ings

How are complex data types saved and restored when used as User-scoped
Application Settings? For an example of what I'm trying to do that does not
work, take the following:

A project has a user-scoped Settings object called "TestString s" which is of
type "StringDictiona ry". The following code is run:

if (Settings.Defau lt.TestStrings == null)
Settings.Defaul t.TestStrings = new StringDictionar y();
Settings.Defaul t.TestStrings.A dd("Test", "Value");
Settings.Defaul t.Save();

Stepping through that code reveals that at each line, the proper action is
performed successfully -- TestStrings is instantiated as a new dictionary,
and a new KeyValuePair is added to it. But each time this program is run,
TestString is *always* null. Other string variables stored in the same
Settings instance are loaded and saved correctly, but TestStrings is not.

Are there any special tricks to dealing with complex objects in
ApplicationSett ings?

May 17 '06 #1
2 12820
Hi,

Thank you for posting!

The problem that StringDictionar y type settings is not saved is because it
doesn't have a TypeConverter and not xml serializable.

There are two primary mechanisms that ApplicationSett ingsBase uses to
serialize settings:
1) If a TypeConverter exists that can convert to and from string, we use it.
2) If not, we fallback to the XmlSerializer.

Here we can derive a custom type from StringDictionar y and either implement
a TypeConverter for it or implement IXmlSerializabl e.

Following is a sample which implements IXmlSerializabl e:

public class SerializableStr ingDictionary : StringDictionar y,
IXmlSerializabl e
{

#region Node class
[Serializable]
public class Node
{
public Node()
{ }

public Node(string k, string v)
{
key = k;
val = v;
}

public string key;
public string val;
}

#endregion Node class for XML Serialization

#region IXmlSerializabl e Members

public System.Xml.Sche ma.XmlSchema GetSchema()
{
return null;
}

public void ReadXml(System. Xml.XmlReader reader)
{
XmlSerializer x = new
XmlSerializer(t ypeof(System.Co llections.Array List), new System.Type[] {
typeof(Node) });

reader.Read();
ArrayList list = x.Deserialize(r eader) as ArrayList;

if (list == null)
return;

foreach (Node node in list)
{
Add(node.key, node.val);
}
}

public void WriteXml(System .Xml.XmlWriter writer)
{
XmlSerializer x = new
XmlSerializer(t ypeof(System.Co llections.Array List), new System.Type[] {
typeof(Node) });
ArrayList list = new ArrayList();
foreach (string key in this.Keys)
{
list.Add(new Node(key, this[key]));
}
x.Serialize(wri ter, list);
}

#endregion
}
Hope this helps.

Regards,

Walter Wang
Microsoft Online Community Support

=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.

May 18 '06 #2
I'am have the same problem.

Do us have the example in VB.NET or have other solution?

I need urgent this.

Best Regards.
_______________ _______________ ________

"Walter Wang [MSFT]" wrote:
Hi,

Thank you for posting!

The problem that StringDictionar y type settings is not saved is because it
doesn't have a TypeConverter and not xml serializable.

There are two primary mechanisms that ApplicationSett ingsBase uses to
serialize settings:
1) If a TypeConverter exists that can convert to and from string, we use it.
2) If not, we fallback to the XmlSerializer.

Here we can derive a custom type from StringDictionar y and either implement
a TypeConverter for it or implement IXmlSerializabl e.

Following is a sample which implements IXmlSerializabl e:

public class SerializableStr ingDictionary : StringDictionar y,
IXmlSerializabl e
{

#region Node class
[Serializable]
public class Node
{
public Node()
{ }

public Node(string k, string v)
{
key = k;
val = v;
}

public string key;
public string val;
}

#endregion Node class for XML Serialization

#region IXmlSerializabl e Members

public System.Xml.Sche ma.XmlSchema GetSchema()
{
return null;
}

public void ReadXml(System. Xml.XmlReader reader)
{
XmlSerializer x = new
XmlSerializer(t ypeof(System.Co llections.Array List), new System.Type[] {
typeof(Node) });

reader.Read();
ArrayList list = x.Deserialize(r eader) as ArrayList;

if (list == null)
return;

foreach (Node node in list)
{
Add(node.key, node.val);
}
}

public void WriteXml(System .Xml.XmlWriter writer)
{
XmlSerializer x = new
XmlSerializer(t ypeof(System.Co llections.Array List), new System.Type[] {
typeof(Node) });
ArrayList list = new ArrayList();
foreach (string key in this.Keys)
{
list.Add(new Node(key, this[key]));
}
x.Serialize(wri ter, list);
}

#endregion
}
Hope this helps.

Regards,

Walter Wang
Microsoft Online Community Support

=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.

Jul 17 '06 #3

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

Similar topics

17
3154
by: Chris Travers | last post by:
Hi all; I just made an interesting discovery. Not sure if it is a good thing or not, and using it certainly breakes first normal form.... Not even sure if it really works. However, as I am able to CRASH the backend, there is a bug here somewhere... test=# select version(); version
116
7510
by: Mike MacSween | last post by:
S**t for brains strikes again! Why did I do that? When I met the clients and at some point they vaguely asked whether eventually would it be possible to have some people who could read the data and some who couldn't but that it wasn't important right now. And I said, 'sure, we can do that later'. So now I've developed an app without any thought to security and am trying to apply it afterwards. Doh!, doh! and triple doh!
2
3547
by: Pete | last post by:
Before I get started with the question, does anyone have a (single) good book recommendation for database design? Not an Access-specific book, but something geared toward helping me figure out *what the user wants*. I've had brief formal education about data flow diagramming, but I'm looking for ... more, now that I'm actually running into problems I think stem from the fact that my users can't explain what they need done, compounded by...
8
2959
by: Steve Jorgensen | last post by:
Mailing List management is a good example of a case where my conundrum arises. Say there is a m-m relationship between parties and groups - anyone can be a member of any combintation of groups. Now, let's say the user wants to be able to send mailings to people who have various combinations of membership and non-membership in those groups. Here's a medium-complex example: (Knitting Group or Macrame Group) and Active Contact and Mailing...
1
2857
by: louis_la_brocante | last post by:
Dear all, I am having trouble generating a client proxy for a webservice whose methods return a "complex" type. The type is complex in that it is a class whose members are a mix of primitive types and of more elaborate classes implementing IXmlSerializable. The resulting WSDL file for the webservice has two separate schemas in its <types> sections, and the client proxy (generated with wsdl.exe) is missing the definitions of the...
2
3580
by: (PeteCresswell) | last post by:
Seems like the toolkit does not handle complex data types. But that seems like much of the real world - once you get past something like just looking up a SIC code or adding two numbers. I see something about the SOAP 2.0 toolkit... then I see that there's a SOAP 3.0... and then I see a note somewhere something like "Support for SOAP 3.0 will be discontinued on (sometime in 2005)".
0
1166
by: greg | last post by:
We have a set of .NET web services to provide access to our data. They use complex data types for both incoming data and return data. We are attempting to help another group access this web service from vbscript/ASP. Is this possible? I have found a few posts scattered around the internet saying complex data types aren't possible with vbscript. Is this true? Can I manually create my XML document in the vbscript, pass it to the web...
2
9781
by: Arvid Requate | last post by:
Hello, I'd like to understand why the following code does not compile. It looks like a strangeness in connection with overload resolution for the <complex> header: The conversion operator double() of class B is called for the member complex::operator*=(double) as expected, but not for operator*(complex, double). The effect is, that the template matching (or overload resolution)
2
1715
by: ma740988 | last post by:
I'm looking for an equivalent approach to what I would do in C++ such to create a vector of vector of complex. I would do : typedef std::vector < std::complex < double complex_dvec; typedef std::vector < complex_dvec twod_complex_vec; int main() { twod_complex_vec tdv ( 3, 3 ); for ( size_t idx ( 0 ); idx < tdv.size(); ++idx ) {
11
2415
by: jacob navia | last post by:
hi I am trying to use the complex data type. Consider this code, taken from the cclib library: struct complex csqrt(Cpx z) { double r; r=sqrt(z.re*z.re+z.im*z.im); r=sqrt(ldexp(r+fabs(z.re),-1));
0
8671
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
8598
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
8887
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
8856
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
7709
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
5858
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
4360
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...
0
4613
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2321
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.