Hi,
I work against .NET 2.0 using C# 2.0. I am facing a problem trying to
serialize the class foo (given below). Basically, foo can contain
other foos in a list. When I try to create a serializer, using the
test() method below, I get a superb StackOverflowEx ception. I googled
for it but didn't found any answer to why I got this exception and how
to serialize foo.
Any help accepted :-)
Thanks,
public void test()
{
XmlSerializer serializer = new XmlSerializer(t ypeof(foo));
....
}
[Serializable]
public class foo : IEnumerable<foo >
{
// ... some members...
List<foog;
public foo()
{
g = new List<foo>();
}
public IEnumerator<foo GetEnumerator()
{
foreach (foo element in g)
{
yield return element;
}
}
System.Collecti ons.IEnumerator
System.Collecti ons.IEnumerable .GetEnumerator( )
{
return GetEnumerator() ;
}
public void Add(Object e)
{
g.Add(e as foo);
}
} 2 4087
The problem here comes from the fact that you are implementing
IEnumerable<Ton T itself (in this case foo). You are better of creating a
container class which implements IEnumerable<foo and then serialize that.
Also, you don't need to the Serializable attribute when using XML
Serialization.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
<et************ @fr.michelin.co mwrote in message
news:11******** **************@ 19g2000hsx.goog legroups.com...
Hi,
I work against .NET 2.0 using C# 2.0. I am facing a problem trying to
serialize the class foo (given below). Basically, foo can contain
other foos in a list. When I try to create a serializer, using the
test() method below, I get a superb StackOverflowEx ception. I googled
for it but didn't found any answer to why I got this exception and how
to serialize foo.
Any help accepted :-)
Thanks,
public void test()
{
XmlSerializer serializer = new XmlSerializer(t ypeof(foo));
...
}
[Serializable]
public class foo : IEnumerable<foo >
{
// ... some members...
List<foog;
public foo()
{
g = new List<foo>();
}
public IEnumerator<foo GetEnumerator()
{
foreach (foo element in g)
{
yield return element;
}
}
System.Collecti ons.IEnumerator
System.Collecti ons.IEnumerable .GetEnumerator( )
{
return GetEnumerator() ;
}
public void Add(Object e)
{
g.Add(e as foo);
}
}
Your foo.g member is recursive. You need an object-reference type of
serialization. The easiest fix for you would be to upgrade to WCF
(.NET 3.0) and use the DataContractSer ializer with its support for
object references. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Jesee |
last post by:
I am reading Jeffrey Richter's book "Applied Microsoft .NET Framework
programming",i came across "Exception handing". Page 405 says
"If the stack overflow occurs within the CLR itself,your application code
won't be able to catch the StackOverflowException exception and none of your
finally blocks will excute.",I don't understand it.
Following...
|
by: Elizabeth |
last post by:
I have C# dll which I compile using ComInterop True and generate tlb
type library. When I call function from the C# dll using below code I
get an error
"StackOverflowException in mscorlib.dll"
Excel vba code:
sub callwrapper()
dim oxml as object
dim sreturnxml as string, spassxmlstring as string
|
by: Alx Sharp |
last post by:
Hello group...
I've created a collection class that implements the following interfaces: IBindingList, IList, ICollection, IEnumerable and ITypedList:
abstract class DataCollectionBase : IBindingList, IList, ICollection, IEnumerable, ITypedList
{
private ArrayList innerList = null;
private System.Type itemType = null;
public...
|
by: zapov |
last post by:
Hi!
I'm having some wierd problems with this exception (error).
If I use sql commands to insert data into sql server i get
strange behaviour from my application.
First I used a single threaded application and used
Application.DoEvents() when i needed to wait some time.
(I need to process some external information on events
so I can't...
|
by: Patrick.O.Ige |
last post by:
Error:-
System.StackOverflowException: Exception of type
System.StackOverflowException was thrown.
When is this thrown..
Any ideas
| |
by: Lars-Erik Aabech |
last post by:
Hi!
I've got an asp.net page that works for all users except one and that one
user only gets the error with a certain parameter set to a certain value.
(Same value as the others, but for this one it fails). I manage to reproduce
the error on my development computer, but it's completely impossible to
debug or trace the error. The page had...
|
by: Mae Lim |
last post by:
Dear all,
I'm new to C# WebServices. I compile the WebService project it return no
errors "Build: 1 succeeded, 0 failed, 0 skipped".
Basically I have 2 WebMethod, when I try to invoke the first method it is
working fine. Then when I try to invoke the second method it return me an
error, Just In-Time Debugging, with error message
"An...
|
by: Thomee Wright |
last post by:
I'm having a problem with a pair of applications I'm developing. I have a
server application which interacts with several instruments, and a client app
which connects to the server and provides a UI for interacting with the
instruments. Readings from the instruments are periodically sent to the
clients, and clients will send commands to the...
|
by: =?Utf-8?B?d2luZHNpbQ==?= |
last post by:
Hi,
I have a project based on .Net 1.1 and VS 2003,now I am trying to upgrade it
to .Net 2.0 and VS 2005.The project passes the 'Build Solution',but When I
start Debug, it suddenly comes StackOverflowException and Debug stops.
The main Exception point is the function below:
public System.ComponentModel.PropertyDescriptorCollection...
|
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...
|
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...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
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...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |