473,791 Members | 3,229 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Issues with XML Deserialization of List<CustomObje ct>

7 New Member
have an object (InputFile) that I am able to successfully serialize to XML and deserialize back into the object through an IXmlSerializabl e interface.

Now I'm trying to serialize a List<InputFile> to XML. I'm using the following code:


Expand|Select|Wrap|Line Numbers
  1. XmlSerializer s = new XmlSerializer(typeof(List<Inputs.InputFile>));
  2. TextWriter w = new StreamWriter("c:\\out.xml");
  3. XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
  4. ns.Add("", "");
  5. w.Serialize(w, Global.Pool.InputFiles, ns);
  6. w.Close();
This produces the following XML:


Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <ArrayOfInputFile>
  3.   <InputFile FileName="file1.hdr" GUID="XYZ" TimeShift="0">
  4.   //objects from a list in the InputFile list
  5.   </InputFile>
  6.   <InputFile FileName="file2.hdr" GUID="ABC" TimeShift="0">
  7.   //objects from a list in the InputFile list
  8.   </InputFile>
  9. </ArrayOfInputFile>
This looks well formed and good to me.

I use the following to deserialize:


Expand|Select|Wrap|Line Numbers
  1. XmlSerializer s = new XmlSerializer(typeof(Inputs.InputFile));
  2. TextReader r = new StreamReader("c:\\out.xml");
  3. List<Inputs.InputFile> a = (List<Inputs.InputFile>)s.Deserialize(r);
  4. r.Close();
I get an exception on the Deserialize line:
InvalidOperatio nException: {"There is an error in XML document (2, 2)."}
{"<ArrayOfInput File xmlns=''> was not expected."}

I've had no issues Serializing/Deserializing List<>s before.

I've tried variations on providing a fake-namespace or removing the namespace portion altogether. Either way I get an InvalidOperatio nException: {"There is an error in XML document (2, 2)."} (2,2 cooresponds to the A in ArrayOfInputFil e): {"<ArrayOfInput File xmlns=''> was not expected."}


Any ideas where I went wrong?

Thanks
Oct 2 '09 #1
3 8478
GaryTexmo
1,501 Recognized Expert Top Contributor
I'm... at a loss! I've done this fairly recently and it went off without a hitch. The only issue I ran into was the code putting a namespace in, which I solved with the exact same approach you used (I wonder if we found the same article :D).

I can't help but wonder why you're getting that error though... clearly your XML has no namespace in it, so I'm not sure why it's saying it does in the exception. Maybe verify 100% that you're looking at the file you think you are. I've done that a few times where I mix things up and realize I'm looking at the wrong file, especially when I switch between build modes in Visual Studio.

Another random thought... is there anything about namespaces in your class code (those items in square brackets) where you define your XML elements/attributes?
Oct 2 '09 #2
Stubbie
7 New Member
You'll notice in my deserialization I used Inputs.InputFil e instead of List<Inputs.Inp utFile>. That simple change makes everything work!
Oct 2 '09 #3
GaryTexmo
1,501 Recognized Expert Top Contributor
Ahhh in the typeof! I missed it too :D Glad you got it working!
Oct 2 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1033
by: dave v | last post by:
I thought I read in an earlier post that there are known issues with deserialization in the System.Data.OracleClient.dll. Can anyone expand on that or give a workaround? I'm calling a custom database component that uses ODP.NET from a BizTalk 2004 map. When this component throws a System.Data.OracleClient.OracleException, I get this in the EventLog: Failed while creating a NUSTestHarness.NUSTest service.
0
1254
by: Christopher Pragash | last post by:
Hello All, I'm trying to use XML Serialization to a class that inherits from another class and also has ArrayLists exposed as properties. When I serialize the class after populating the methods I get the following XML: <?xml version="1.0" encoding="utf-16"?> <Bulletin xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <MetaData>MetaData</MetaData>
0
1772
by: pak76 | last post by:
Class SignedXml is used to produce/verify signature over XML document. One of its methods, function GetIdElement, is used to select Xml elements for signature and verification and consist following line: xmlElement = document.SelectSingleNode(String.Concat("//*")) is XmlElement; I can see two issues with this line 1. URI injection - there is no validation of idValue whatsoever; therefore I can successfully validate document below (see...
2
3825
by: Snowman | last post by:
Suppose I have a RootObject which holds a collection of other objects. The other objects have a property (Parent) which refers back to the "parent" collection (b.t.w. my collection is based on CollectionBase), in similar fashion as the object models of MS Office. I want to serialize this object graph (with RootObject as the xml document element) without Parent property serialized, this may be done by adding XmlIgnoreAttribute on the...
4
3156
by: Mike Sarbu | last post by:
Hello all, I have an XML file like this: <?xml version="1.0" encoding="utf-8"?> <SomeObject xmlns="http://www.abcinc.com/objectdefinition" xmlns:someobj=http://www.abcinc.com/objectdefinition> ...... </SomeObject>
3
9796
by: parrot toes | last post by:
Summary: I have been trying to make requests of a web service provided by Axis using a dotnet client with code generated by wsdl.exe and have been getting exceptions when trying to process the response. As a result of seraching news groups I guessed that the SOAP response defines an array element in a way that causes the dotnet deserialization routines to put the content in a generic object array (object) BUT the content is supposed to...
1
3752
by: parrot toes | last post by:
I tried to post this question before, but there was an error when posting. I case it did get posted and in order to avoid duplication, I'll just repost a summary. I have written a dotnet client that accesses a Axis provided web service. The client uses the code generated, using wsdl.exe, from the wsdl file provided by the web service provider. The web response has the following schema (roughly):
8
3470
by: ashoksrini | last post by:
Hi All, I have the below requirement and would like to get some feeback from the group on the best way to implement: 1. I have WSDL defined exposing few web services. 2. We dont have a requirement to have a server web service class. (reasons below) 3. I want to develop something like this - when client makes a web service call, on the server I can intercept the SOAP message (XML doc itself),
2
1287
by: Joe | last post by:
I'm getting this strange error: The object with ID 203 was referenced in a fixup but does not exist. I get different numbers depending on the file I'm trying to deserialize. Any idea what it means? -Joe
6
4019
by: Bradley Plett | last post by:
I have run into this problem occasionally, and have crude ways of getting around it, but I'm wondering if anyone else has a better, more elegant solution. I have a web service and a client application that share a class. For one of my web service methods, for example, I return an object of the given class type. However, when I try to cast the object in my client, I run into a namespace conflict. This makes sense to me, but if I...
0
9666
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, 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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10419
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, 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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10147
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9987
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 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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7531
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5552
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4100
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3709
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2910
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.