From: Tony Johansson on
Hello!

What does it mean what it says that you cannot serialize object graphs; you
can use XML serialization only on objects ?

//Tony



From: Martin Honnen on
Tony Johansson wrote:

> What does it mean what it says that you cannot serialize object graphs; you
> can use XML serialization only on objects ?

I think that an object graph can contain cycles and that XmlSerializer
cannot deal with cycles.


--

Martin Honnen --- MVP Data Platform Development
http://msmvps.com/blogs/martin_honnen/
From: Tony Johansson on
"Martin Honnen" <mahotrash(a)yahoo.de> skrev i meddelandet
news:OqUExkVCLHA.2012(a)TK2MSFTNGP02.phx.gbl...
> Tony Johansson wrote:
>
>> What does it mean what it says that you cannot serialize object graphs;
>> you can use XML serialization only on objects ?
>
> I think that an object graph can contain cycles and that XmlSerializer
> cannot deal with cycles.
>
>
> --
>
> Martin Honnen --- MVP Data Platform Development
> http://msmvps.com/blogs/martin_honnen/

Can you give a simple example ?

//Tony


From: Peter Duniho on
Tony Johansson wrote:
> "Martin Honnen" <mahotrash(a)yahoo.de> skrev i meddelandet
> news:OqUExkVCLHA.2012(a)TK2MSFTNGP02.phx.gbl...
>> Tony Johansson wrote:
>>
>>> What does it mean what it says that you cannot serialize object graphs;
>>> you can use XML serialization only on objects ?

What does what mean? In the above sentence, do what does "it" refer?

>> I think that an object graph can contain cycles and that XmlSerializer
>> cannot deal with cycles.
>
> Can you give a simple example ?

class A
{
public B B { get; set; }
}

class B
{
public A A { get; set; }
}

class C
{
public void SerializeA()
{
A a = new A();
B b = new B();

a.B = b;
b.A = a;

// Serialize here (or try to!)
}
}

That said, not all object graphs have cycles, and AFAIK the .NET
serialization stuff doesn't have problems with acyclic graphics. Is
this question yet another from that awful study materials you've been using?

Pete
From: Arne Vajhøj on
On 11-06-2010 10:06, Tony Johansson wrote:
> "Martin Honnen"<mahotrash(a)yahoo.de> skrev i meddelandet
> news:OqUExkVCLHA.2012(a)TK2MSFTNGP02.phx.gbl...
>> Tony Johansson wrote:
>>> What does it mean what it says that you cannot serialize object graphs;
>>> you can use XML serialization only on objects ?
>>
>> I think that an object graph can contain cycles and that XmlSerializer
>> cannot deal with cycles.
>
> Can you give a simple example ?

using System;
using System.Xml.Serialization;

namespace E
{
public class C1
{
public C2 Other { get; set; }
}
public class C2
{
public C1 Other { get; set; }
}
public class Program
{
public static void Main(string[] args)
{
C1 o1 = new C1();
C2 o2 = new C2();
o1.Other = o2;
o2.Other = o1;
XmlSerializer ser = new XmlSerializer(typeof(C1));
ser.Serialize(Console.Out, o1);
Console.ReadKey();
}
}
}

gives:

System.InvalidOperationException: There was an error generating the XML
document. ---> System.InvalidOperationException: A circular reference
was detected while serializing an object of type E.C1.
at System.Xml.Serialization.XmlSerializer.Serialize
at System.Xml.Serialization.XmlSerializer.Serialize
at System.Xml.Serialization.XmlSerializer.Serialize
at E.Program.Main

Arne