473,385 Members | 1,720 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,385 software developers and data experts.

Problems with Deserialization...

Hi,

I'm having problems with some very simple deserialization code
and would appreciate it very much if I could get some help here.

The following is the code:
================================================== =======
XmlReader reader = new XmlTextReader("test.xml");
XmlValidatingReader vr = new XmlValidatingReader(reader);

try
{
while (vr.Read()){}

XmlSerializer xs = new XmlSerializer(typeof(Event));
ev = (Event)xs.Deserialize(reader);
}
catch (Exception e)
{
System.Console.WriteLine(e.Message);
}

System.Console.WriteLine(ev.Config.User); <<<< This is where it bombs
================================================== ========

My XML and XSD:
================================================== ====
<?xml version="1.0" encoding="utf-8"?>
<Event xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="C:\Web400\contract\ test.xsd">
<Config>
<Ticket>1</Ticket>
<User>Smith</User>
</Config>
</Event>
================================================== ===
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xs:element name="Event">
<xs:complexType>
<xs:sequence>
<xs:element name="Config">
<xs:complexType>
<xs:sequence>
<xs:element name="Ticket" type="xs:int"/>
<xs:element name="User" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
================================================== ============

The only way I can make my XML look like this:

<?xml version="1.0" encoding="utf-8"?>
<Event xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="C:\Web400\contract\ test.xsd">
<Config xmlns="http://tempuri.org">
<Ticket>1</Ticket>
<User>Smith</User>
</Config>
</Event>

but the problem is I'll have to comment out the code that
validates the XML against the schema since the above XML won't pass.
What am I missing here?

-Linus
Nov 12 '05 #1
1 1530
Linus wrote:
Hi,

I'm having problems with some very simple deserialization code
and would appreciate it very much if I could get some help here.
while (vr.Read()){}
XmlSerializer xs = new XmlSerializer(typeof(Event));
ev = (Event)xs.Deserialize(reader); System.Console.WriteLine(ev.Config.User); <<<< This is where it bombs


1. I do not understand what for "while (vr.Read()){}"
2. After 1) your stream position will point at the end of file, right?
So what the object do you expect to be read at the eof() position?
Probably it returns null, that successfuly is casted to Event class.
I suppose that "bombs" means "null reference exception"?

Vadim Chekan.

Nov 12 '05 #2

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

Similar topics

2
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...
3
by: AnkitAsDeveloper [Ankit] | last post by:
Hi i am serializing a 'ref struct' object as follows : private: void Seri( String ^path, Object^ obj ) { FileStream^ fileStrm ; try { //Serialize entire object into Binary stream
3
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...
1
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...
8
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...
5
by: frustratedWithDotNet | last post by:
Why does .NET not issue messages or throw exceptions if it doesn't like something in the response from a web service?? I am getting a response object, but an array of custom objects within the...
5
by: Greg Allen | last post by:
I am consuming a web service and using the generated Reference.cs to access the service and the objects associated with it. I have run into a problem where some inherited classes are not being...
1
by: Gregor D. | last post by:
Hi, I want to consume an Apache Webservice with a C# .NET Client. Everything works fine, but I'm having problem with the deserialization of the complex type "Item" that is included in the...
7
by: Andrew | last post by:
Hi, I am using DataContractJsonSerializer to deserialize JSON string in C# objects but I am having a problem. Suppose I have a class: class Item { public ItemId Id { get; set; }
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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
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
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...

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.