473,399 Members | 2,278 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,399 software developers and data experts.

Serialization problems

Hi Group

I have homemade class, lets call it firstclass, and then another class
(secondclass) which contains an ArrayList of firstclass objects.

When I try to xml serialize secondclass with the arraylist in it I get an
errormessage saying "The type <TheNameSpace>.<TheFirstClass> was not
expected. Use the XmlInclude or SoapInclude attribute to specify types that
are not known statically."

I dont have the slightest clue about what to do here, and I can't find
anything on the web about it.

...TheCow
Nov 11 '05 #1
1 2417
Hi TheCow,

You need to declare the type of the objects stored inside the ArrayList in
order for the XmlSerializer to process it properly. You can declare the
types by attaching XmlElement or XmlArrayItem attributes with the Type
property set to the types in the ArrayList to the ArrayList field:

public class foo
{
[XmlElement( Type=(typeof(baz) )]
public ArrayList bar;
}

or you can pass them to the constructor of the XmlSerializer:

XmlSerializer ser = new XmlSerializer( typeof( foo ), new Type[] { typeof
( baz ) } );

HTH,
Christoph Schittko
Software Architect, .NET Mentor
MS MVP XML .NET

You can do that either via the XmlInclude attribute
"TheCow" <co*@cow.cow> wrote in message
news:bh**********@news.net.uni-c.dk...
Hi Group

I have homemade class, lets call it firstclass, and then another class
(secondclass) which contains an ArrayList of firstclass objects.

When I try to xml serialize secondclass with the arraylist in it I get an
errormessage saying "The type <TheNameSpace>.<TheFirstClass> was not
expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically."

I dont have the slightest clue about what to do here, and I can't find
anything on the web about it.

..TheCow

Nov 11 '05 #2

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

Similar topics

2
by: Ante Sabo | last post by:
Hello, It seems to me to be in some kinda trouble. I wanted to implement communication between Java applet and Server through sockets and Serialization. So, I serialize Object, send it to server...
3
by: AA | last post by:
Hello I am having problems with a very simple serialization :( I download the schema http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-5-MM7-1-0 and execute the xsd.exe for...
0
by: HakonB | last post by:
Hi all I get an exception when trying to deserialize a simple configuration file using XML Serialization. The very long stacktrace can be seen at the bottom of this message. I've see other...
2
by: Dominic | last post by:
Hi everybody, I'm planning to use serialization to persist an object (and possibly its child objects) in my application. However, I'm concerned about the backward compatibility issue. I'm...
4
by: Brian Keating | last post by:
wonder if anyone can help me here, i've a framework 1.1 dataset which i serialize in framework 1.1 and deserialize in framework 2.0. This is fine, problem is that i want to modify some of the...
0
by: Goethals Frederik | last post by:
Hi, I have some questions that are a little difficult to explain, so I give it a try... I have an application (aSP.NET with VB.NET codebehind) and I would like to store my data on disk...
3
by: Paulo Morgado [MVP] | last post by:
Hi all ..NET Framework 1.1 I have created several types that are serailized to XML as strings. Someting like this: public struct MyInt32 : IXmlSerializable { int value;
5
by: Harold Howe | last post by:
I am having a problem deserializing objects from a library when the following conditions exist: 1- The library is strongly named 2- The serialized file was created with version 1.0 of the...
5
by: RobinS | last post by:
I want to serialize a class that I am using to retain some information the user types into a screen. I have 3 questions. 1) I serialized it as XML to start with. This works, but how do I...
1
by: kikisan | last post by:
I am developing a windows service which utilizes the following classes: interface IPersistable; abstract class PersistableObject : IPersistable;
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
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.