473,699 Members | 2,701 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

HELP Problem serializing a structure

Hello,

I am having a problem trying to serialize this simple structure, I use it
in a collection class that derives from CollectionBase but I noticed that at
least for now the serialization exception ocurrs when i try to serialize
this structure (see below). The idea is that it would be serialized to:

< Param type="..." method="Get" required="true" >something</Param>

I use the following to serialize:

WizarParameter wpar = new WizardParameter (typeof(int),
WizardParameter Method.Get, true, "something" );
StringWriter sw = new StringWriter();
XmlSerializer ser = new XmlSerializer(t ypeof(WizardPar ameter));
ser.Serialize(s w, wpar);

[Serializable]
[XmlRoot("Param" )]
public struct WizardParameter

{

/// The system type contained by this parameter
[XmlAttribute("t ype")]
public System.Type Type;

/// The method that should be used to pass this paramete
[XmlAttribute("m ethod")]
public WizardParameter Method Method; /// enumeration

/// Whether the parameter is required or optional

[XmlAttribute("r equired")]
public bool IsRequired;

[XmlElement("key ")]
public string Key;

public WizardParameter (Type type, WizardParameter Method method, bool
required, string key)

{

this.Type = type;

this.Method = method;

this.IsRequired = required;

this.Key = key;

}

}
Nov 17 '05 #1
3 10805
Ed,

What are the details of the exception? I believe that you can't do this
properly because the XmlSerializer will only access public properties, and
can not access indexers either (which is how you would get the items in the
collection).

You might want to use the SoapFormatter (depending on how readable you
want the content to be).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"~~~ .NET Ed ~~~" <ti*********@ab olishspam.now> wrote in message
news:eO******** ******@TK2MSFTN GP15.phx.gbl...
Hello,

I am having a problem trying to serialize this simple structure, I use
it in a collection class that derives from CollectionBase but I noticed
that at least for now the serialization exception ocurrs when i try to
serialize this structure (see below). The idea is that it would be
serialized to:

< Param type="..." method="Get" required="true" >something</Param>

I use the following to serialize:

WizarParameter wpar = new WizardParameter (typeof(int),
WizardParameter Method.Get, true, "something" );
StringWriter sw = new StringWriter();
XmlSerializer ser = new XmlSerializer(t ypeof(WizardPar ameter));
ser.Serialize(s w, wpar);

[Serializable]
[XmlRoot("Param" )]
public struct WizardParameter

{

/// The system type contained by this parameter
[XmlAttribute("t ype")]
public System.Type Type;

/// The method that should be used to pass this paramete
[XmlAttribute("m ethod")]
public WizardParameter Method Method; /// enumeration

/// Whether the parameter is required or optional

[XmlAttribute("r equired")]
public bool IsRequired;

[XmlElement("key ")]
public string Key;

public WizardParameter (Type type, WizardParameter Method method, bool
required, string key)

{

this.Type = type;

this.Method = method;

this.IsRequired = required;

this.Key = key;

}

}

Nov 17 '05 #2
Well I guess I will worry about the collection serialization when the time
comes. For now my problem is that this simple structure with four public
members (of which three should be serialized as attribute and the other as
inner text) and no indexers throws an InvalidOperatio nException with "There
was an error reflecting type WizardParameter " message.

Any ideas? I don't see why such a simple structure would not serialize. This
structure in particular should serialize as given below (a single element
with 3 attributes and inner text).

Emil

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote in
message news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
Ed,

What are the details of the exception? I believe that you can't do
this properly because the XmlSerializer will only access public
properties, and can not access indexers either (which is how you would get
the items in the collection).

You might want to use the SoapFormatter (depending on how readable you
want the content to be).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"~~~ .NET Ed ~~~" <ti*********@ab olishspam.now> wrote in message
news:eO******** ******@TK2MSFTN GP15.phx.gbl...
Hello,

I am having a problem trying to serialize this simple structure, I use
it in a collection class that derives from CollectionBase but I noticed
that at least for now the serialization exception ocurrs when i try to
serialize this structure (see below). The idea is that it would be
serialized to:

< Param type="..." method="Get"
required="true" >something</Param>

I use the following to serialize:

WizarParameter wpar = new WizardParameter (typeof(int),
WizardParameter Method.Get, true, "something" );
StringWriter sw = new StringWriter();
XmlSerializer ser = new XmlSerializer(t ypeof(WizardPar ameter));
ser.Serialize(s w, wpar);

[Serializable]
[XmlRoot("Param" )]
public struct WizardParameter

{

/// The system type contained by this parameter
[XmlAttribute("t ype")]
public System.Type Type;

/// The method that should be used to pass this paramete
[XmlAttribute("m ethod")]
public WizardParameter Method Method; /// enumeration

/// Whether the parameter is required or optional

[XmlAttribute("r equired")]
public bool IsRequired;

[XmlElement("key ")]
public string Key;

public WizardParameter (Type type, WizardParameter Method method, bool
required, string key)

{

this.Type = type;

this.Method = method;

this.IsRequired = required;

this.Key = key;

}

}


Nov 17 '05 #3
I finally found out, the message given was not enough, but exploring the
actual exception object generated told me the culprit was the Type property.
For some reason it is not able to serialize a member of type System.Type.
Since I don't have more time to spend on it I worked around it by converting
the member to a string and simply using x.GetType().ToS tring() now both the
structure (items) and the custom collection (based on CollectionBase)
serialize properly and with the element/attribute names I chose.

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c om> wrote in
message news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
Ed,

What are the details of the exception? I believe that you can't do
this properly because the XmlSerializer will only access public
properties, and can not access indexers either (which is how you would get
the items in the collection).

You might want to use the SoapFormatter (depending on how readable you
want the content to be).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"~~~ .NET Ed ~~~" <ti*********@ab olishspam.now> wrote in message
news:eO******** ******@TK2MSFTN GP15.phx.gbl...
Hello,

I am having a problem trying to serialize this simple structure, I use
it in a collection class that derives from CollectionBase but I noticed
that at least for now the serialization exception ocurrs when i try to
serialize this structure (see below). The idea is that it would be
serialized to:

< Param type="..." method="Get"
required="true" >something</Param>

I use the following to serialize:

WizarParameter wpar = new WizardParameter (typeof(int),
WizardParameter Method.Get, true, "something" );
StringWriter sw = new StringWriter();
XmlSerializer ser = new XmlSerializer(t ypeof(WizardPar ameter));
ser.Serialize(s w, wpar);

[Serializable]
[XmlRoot("Param" )]
public struct WizardParameter

{

/// The system type contained by this parameter
[XmlAttribute("t ype")]
public System.Type Type;

/// The method that should be used to pass this paramete
[XmlAttribute("m ethod")]
public WizardParameter Method Method; /// enumeration

/// Whether the parameter is required or optional

[XmlAttribute("r equired")]
public bool IsRequired;

[XmlElement("key ")]
public string Key;

public WizardParameter (Type type, WizardParameter Method method, bool
required, string key)

{

this.Type = type;

this.Method = method;

this.IsRequired = required;

this.Key = key;

}

}


Nov 17 '05 #4

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

Similar topics

0
2123
by: rgerla | last post by:
I'm trying to serialize a compount structure set for a web service, the sturctures are something like this: Public Structure UserPhone Public phonenumber As String Public phonetype As Char End Structure Public Structure userdata Public firstname As String Public lastname As String
0
1169
by: rgerla | last post by:
I'm trying to serialize a compount structure set for a web service, the sturctures are something like this: Public Structure UserPhone Public phonenumber As String Public phonetype As Char End Structure Public Structure userdata Public firstname As String Public lastname As String
10
8284
by: copx | last post by:
I want to save a struct to disk.... as plain text. At the moment I do it with a function that just writes the data using fprintf. I mean like this: fprintf(fp, "%d %d", my_struct.a, my_struct.b) This way I have to write another "serializing" function for every new kind of struct I want to write, though. Is there a way to write functions that can write/read any struct to/from plain text format in a portable way?
5
4790
by: Alfonso Morra | last post by:
Hi, I am writing a messaging library which will allow me to send a generic message structure with custom "payloads". In many cases, a message must store a non-linear data structure (i.e. "payload") using pointers. Examples of these are binary trees, hash tables etc. Thus, the message itself contains only a pointer to the actual data. When the message is sent to the same processor, these pointers point to the original locations, which...
2
3517
by: Tobias Zimmergren | last post by:
Hi, just wondering what serializing really is, and howto use it? Thanks. Tobias __________________________________________________________________ Tobias ICQ#: 55986339 Current ICQ status: + More ways to contact me __________________________________________________________________
0
1409
by: olsonchris | last post by:
Hello all, I have what appears to be a simple question but after quite a bit of research I can't seem to find an answer. Basically, I am serializing a class into an XML document. This is creating a XML doc that includes the following: <Document:File> <buffer>JKDIDIEJ</buffer> </Document:File>
6
3176
by: Kyle Teague | last post by:
What would give better performance, serializing a multidimensional array and storing it in a single entry in a table or storing each element of the array in a separate table and associating the entries with the entry in the other table? Having a separate table would result in two queries instead of one, but you wouldn't have to deal with the overhead of serializing and unserializing data. -- Kyle
2
2882
by: =?Utf-8?B?UmF5IE1pdGNoZWxs?= | last post by:
Hi, I know this will sound like a lot of hand waving, and I'll be glad to supply some sample code if necessary, but I thought something obvious might jump out at someone without doing so. Anyway, I have a structure that has several members including an array of strings. I assign the elements of the string array from the .Text property of several TextBoxes. I then serialize the structure and write it to a file. However, when I...
12
4914
by: Cagdas Ozgenc | last post by:
Greetings, When directly serializing C++ structures to a file with the standard library functions giving the address of the data and length of structure using the sizeof operator, do I risk portability because of different compilers packing structures into different sizes or components of this structure to different address boundaries (for example placing in multiples of 4 on a 32bit system)? Once the file is serialized, does the same...
0
8615
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,...
0
9033
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8911
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
8882
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
7748
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
5872
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
4375
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
3057
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2009
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.