473,398 Members | 2,088 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

XmlSerializationWriter - Specified cast is not valid

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 "

Nov 16 '05 #1
7 3440
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."

Nov 16 '05 #2
So how can I serialize such structure?

--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "
"Kevin Yu [MSFT]" <v-****@online.microsoft.com> wrote in message
news:zk**************@cpmsftngxa06.phx.gbl...
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."

Nov 16 '05 #3
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
Nov 16 '05 #4
Outlook Express NewsReader add it automatic. Sorry

--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "
"Simon Smith" <gh*****@community.nospam> wrote in message
news:ba******************************@ghytred.com. ..
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

Nov 16 '05 #5
Hi Tamir,

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

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

Nov 16 '05 #6
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-****@online.microsoft.com> wrote in message
news:82**************@cpmsftngxa06.phx.gbl...
Hi Tamir,

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

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

Nov 16 '05 #7
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.

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

Nov 16 '05 #8

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

Similar topics

0
by: Tao | last post by:
I just upgraded .NET framework to 1.1 and VS.Net to 2003 version and tried to test it out. I created an ASP.NET project using the wizard and tried to run it by hitting "F5". I got an exception:...
4
by: Tyro | last post by:
Can someone shed some light on my error here? Thanks! Specified cast is not valid. Exception Details: System.InvalidCastException: Specified cast is not valid. Source Error: Stack Trace:
3
by: PK9 | last post by:
I am looking for assistance in pinpointing the cause of the following exception. I am getting a "Specified Cast is not valid" exception on my page. I am trying to populate a datagrid. One of my...
2
by: Fabian | last post by:
Hi, I work with asp.net 2.0 and I have a intermittent error, only happens a few times a day. In the page I evaluate a Query String and then I get data form a database. The code snipped: ...
3
by: VB Programmer | last post by:
I am setting up forms authentication. In my code I keep getting this error. Any ideas? Error.... Server Error in '/LandOLots' Application....
0
by: QA | last post by:
I am using a Business Scorecard Accelarator in a Sharepoint Portal 2003 using SQL Server 2005 I am getting the following error: Error,5/7/2005 10:50:14 AM,580,AUE1\Administrator,"Specified cast is...
0
by: Alan Z. Scharf | last post by:
this question in datagrid group for several days with no repsonse. I'm hoping for an answer her because of greater activity in this group. No cross-posting intended. Thanks....
3
by: =?Utf-8?B?UGF1bCBQcmV3ZXR0?= | last post by:
I'm attempting to use LINQ to insert a record into a child table and I'm receiving a "Specified cast is not valid" error that has something to do w/ the keys involved. The stack trace is: ...
2
by: vinrin | last post by:
Thank for your answer. :-) call CheckEmptyNode (treeview) public void CheckEmptyNode( Object N ) { Microsoft.Web.UI.WebControls.TreeNode menuNode = null; ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
Oralloy
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,...
0
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...
0
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...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.