Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

XmlSerializationWriter - Specified cast is not valid

18 views
Skip to first unread message

Tamir Khason

unread,
Jul 1, 2004, 9:40:12 AM7/1/04
to
Code
public class RootSerialized
{
[XmlElement("SomeCollection")]
public SomeCollection SomeThings;
}

public class SomeCollection: BaseCollection ,ITypedList ,IBindingList
{
public SomeCollection() : base()
{
}
[XmlElement("Something")]
public Something this[int index]
{
get
{
return (Something )m_al[index];
}
}
}

During the serialization

XmlSerializer s = new XmlSerializer( typeof( RootSerialized ) );

this this structure return error:
System.InvalidOperationException: There was an error generating the XML
document. ---> System.InvalidCastException: Specified cast is not valid.

So what is the problem?

--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "

Kevin Yu [MSFT]

unread,
Jul 2, 2004, 5:25:58 AM7/2/04
to
Hi Tamir,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that when serializing a class, there is an
System.InvalidOperationException, which says "There was an error generating
the XML document." is generated. If there is any misunderstanding, please
feel free to let me know.

Based on my research, this exception is thrown, because the BaseCollection
class is not serializable. This class does not implement the ISerializable
interface and it contains some complex data types. So when the object is
going to be serialized, the Serialize method doesn't know how to convert
data in the object, and the exception is thrown.

HTH.

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

Tamir Khason

unread,
Jul 2, 2004, 7:21:51 AM7/2/04
to
So how can I serialize such structure?

--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "


"Kevin Yu [MSFT]" <v-k...@online.microsoft.com> wrote in message
news:zkw3faBY...@cpmsftngxa06.phx.gbl...

Simon Smith

unread,
Jul 2, 2004, 6:42:29 AM7/2/04
to
On 02 Jul 2004 12:21, "Tamir Khason" wrote:
>So how can I serialize such structure?
>

Implement Iserializable.

(BTW, if you're going to top post, please don't use the sig dash - '--
' - as a lot of newsreaders will cut off quoting text after it, just like
this answer does.)

--
Simon Smith
simon dot s at ghytred dot com
www.ghytred.com/NewsLook - NNTP Client for Outlook


Tamir Khason

unread,
Jul 2, 2004, 3:30:29 PM7/2/04
to
Outlook Express NewsReader add it automatic. Sorry

--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "


"Simon Smith" <ghy...@community.nospam> wrote in message
news:ba6fe32be83e4c1c...@ghytred.com...

Kevin Yu [MSFT]

unread,
Jul 4, 2004, 10:59:20 PM7/4/04
to
Hi Tamir,

To serialize such object, we have to implement ISerialization interface so
that the serializer will know how to serialize this object.

Tamir Khason

unread,
Jul 8, 2004, 6:13:05 AM7/8/04
to
Thank you for your reply. The issue solved by workaround
Are there support for this at FW2.0?

--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "


"Kevin Yu [MSFT]" <v-k...@online.microsoft.com> wrote in message

news:82LwZwjY...@cpmsftngxa06.phx.gbl...

Kevin Yu [MSFT]

unread,
Jul 12, 2004, 1:42:35 AM7/12/04
to
Hi Tamir,

Since .NET framwork 2.0 hasn't been officially release, we are not quite
sure about the feature of it, because everything might be changed before
release.

0 new messages