473,508 Members | 2,744 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem using XMlSerializer.Deserialize

1 New Member
Hi,

I know this is a frequently asked question but have tried several combinations and cant seem to figure this out.

I am serializing my object as follows:
XmlSerializer serializer = new XmlSerializer(data.GetType());
StringWriter writer = new StringWriter();

XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces();
namespaces.Add("", "");
serializer.Serialize(writer, data, namespaces);
string output = writer.ToString();

This produces the desired XML - as in one with no namespaces in it.

Now when I try to deserialize this object as follows:
XmlSerializer serializer = new XmlSerializer(data.GetType());
StringReader reader = new StringReader(data);
System.Xml.XmlTextReader xmlReader = new System.Xml.XmlTextReader (reader);
// I have tried both with and without the following line
xmlReader.Namespaces = false;
object returnValue = serializer.Deserialize(xmlReader);

This throws an error: There is an error in XML document and the message is something on the lines of My object's root node = xmlns was not expected.

I dont understand why this is happenign because my root node does not contain any xmlns attribute.

Also, the solution of defining namespace on class level will not work for me as this is a generic class library.

Any help would be highly appreciated
Thanks
P
Sep 8 '06 #1
0 2006

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

Similar topics

3
2096
by: Mark | last post by:
Hi all, i'm trying to serialize a class. Using the constructor of XmlSerializer i get these (odd?) errors: "File or assembly name goseij9w.dll, or one of its dependencies, was not found"....
5
10027
by: Alexis | last post by:
Hello, I have a set of classes I created from schema files using the xsd.exe tool. I'm using namespaces in the clases ( I had to because I have some classes with the same name but not the same...
1
1665
by: Andrea | last post by:
I was trying to deserialize my xml file (I enclose it below ) into a class. So I generated an xsd file given my xml using the MS xsd tool; then I generated the corresponsing C# class (using the MS...
0
1445
by: David Preuss | last post by:
Hi all, i have a problem with a class which has several subclasses embedded when trying to deserialize it. Serializing works just fine. The xml is as follows: <?xml version="1.0"...
4
3767
by: m96 | last post by:
hi, i have a problem with XmlDeserilisation which drives me crazy. i know i must be missing something very trivial... i'm trying to parse the folling xml file i really would appreciate any...
4
2947
by: pei_world | last post by:
I have followed a example from a book exactly, but it seems not working at all. can anyone tell me what is going on? ========= Global.asax.cs ============ public static Entry...
1
5108
by: Yewen Tang | last post by:
I have a schema file datamodel.xsd, element "properties" is declared as a type of "baseProperty". The schema file also defines "derivedProperty" is a derived type of "baseProperty". <?xml...
1
5740
by: kimtherkelsen | last post by:
Hi, I want to send XML data from a server to some clients over a network connection using the TCP/IP protocol. If I send the XMLs as byte arrays I need to insert header information in the data to...
1
4930
by: depalau | last post by:
I'm experiencing issues where XmlSerialier.Deserialize throws an exception when attempting to use a MemoryStream built with an XmlWriter vs. a standalone StringReader. It is attempting to...
0
7393
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7058
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
7502
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
5635
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,...
1
5057
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...
0
4715
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3191
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
769
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
426
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...

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.