473,698 Members | 2,283 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XML deserializer sees zero-length file, "root element is missing"

MC
I have a couple of customers who are using a program that deserializes an
XML file, and on some files, the program fails to see the content of the
file -- treats it as zero length and reports "root element is missing" --
even though in Notepad the file looks normal.

Has anybody ever seen this? Any clues? I have not been able to reproduce
it on my computer. In general, when they e-mail me the files, the files
arrive perfectly normal. But on one occasion the e-mailed files were
zero-length.

Thanks!

Jun 27 '08 #1
11 3886
"MC" <fo************ **@www.ai.uga.e du.slash.mcwrot e:
I have a couple of customers who are using a program that deserializes
an XML file, and on some files, the program fails to see the content
of the file -- treats it as zero length and reports "root element is
missing" -- even though in Notepad the file looks normal.
Could it be a file permissions issue?

Eq.
Jun 27 '08 #2
On Wed, 23 Apr 2008 06:41:52 -0700, MC
<fo************ **@www.ai.uga.e du.slash.mcwrot e:
I have a couple of customers who are using a program that deserializes
an XML file, and on some files, the program fails to see the content of
the file -- treats it as zero length and reports "root element is
missing" -- even though in Notepad the file looks normal.

Has anybody ever seen this? Any clues? I have not been able to
reproduce it on my computer. In general, when they e-mail me the files,
the files arrive perfectly normal. But on one occasion the e-mailed
files were zero-length.
If the user was able to actually show you a zero-length file at least
once, that makes me suspicious that the other files that aren't
zero-length are not in fact the actual file that was being read. This
could be because the user provided the wrong file, or because you've got
some sort of race condition in which the files were zero-length when your
program tried to read them, but not when the user looked at them later.

How are the files being generated?

Pete
Jun 27 '08 #3
Does your program actually check to see that it is about to deserialize a
well-formed xml document? And handle this expected condition properly? I
realize this may seem obvious...

-- Peter
To be a success, arm yourself with the tools you need and learn how to use
them.

Site: http://www.eggheadcafe.com
http://petesbloggerama.blogspot.com
http://ittyurl.net
"MC" wrote:
I have a couple of customers who are using a program that deserializes an
XML file, and on some files, the program fails to see the content of the
file -- treats it as zero length and reports "root element is missing" --
even though in Notepad the file looks normal.

Has anybody ever seen this? Any clues? I have not been able to reproduce
it on my computer. In general, when they e-mail me the files, the files
arrive perfectly normal. But on one occasion the e-mailed files were
zero-length.

Thanks!

Jun 27 '08 #4

"Paul E Collins" <fi************ ******@CL4.orgw rote in message
news:Hp******** *************** *******@bt.com. ..
"MC" <fo************ **@www.ai.uga.e du.slash.mcwrot e:
>I have a couple of customers who are using a program that deserializes an
XML file, and on some files, the program fails to see the content of the
file -- treats it as zero length and reports "root element is missing" --
even though in Notepad the file looks normal.

Could it be a file permissions issue?
Conceivably. If so, the right exception is not being thrown.

One other clue. Normally, when the customer e-mails me the un-openable
files, they look normal and open just fine in my copy of the software.
Today, however, I was sent two of them which arrived as zero-length files.
So Outlook, or whatever they sent their mail with, had the same problem as
my program trying to open the files.

Jun 27 '08 #5
If the user was able to actually show you a zero-length file at least
once, that makes me suspicious that the other files that aren't
zero-length are not in fact the actual file that was being read.
Good point.
>This could be because the user provided the wrong file, or because you've
got some sort of race condition in which the files were zero-length when
your program tried to read them, but not when the user looked at them
later.

How are the files being generated?
The program is basically for creating and editing files containing a large
data structure.

Loading a file looks like this:

using (StreamReader infile = new StreamReader(ne w FileStream(file name,
FileMode.Open, FileAccess.Read , FileShare.Read) ))
{
XmlSerializer x = new XmlSerializer(t his.GetType());
foo j = (foo)x.Deserial ize(infile); // foo stands for the name of my
big class
infile.Close();
}

Saving a file looks like this:

using (StreamWriter outfile = new StreamWriter(fi lename))
{
XmlSerializer x = new XmlSerializer(t his.GetType());
x.Serialize(out file,this);
outfile.Close() ;
}

Since the loading and saving are done at different times (at least minutes
apart) by the same person, I don't see how it could be a race condition.

Is there some error condition that could result in a zero-length file
(either reading or writing) without throwing an exception?
Jun 27 '08 #6

"Peter Bromberg [C# MVP]" <pb*******@yaho o.NoSpamMaam.co mwrote in message
news:4C******** *************** ***********@mic rosoft.com...
Does your program actually check to see that it is about to deserialize a
well-formed xml document? And handle this expected condition properly? I
realize this may seem obvious...
See other posting. I'm not quite sure what you mean. I use
XmlSerializer.D eserialize. But the next step is going to be to add some
code that first opens the file and looks at it (to verify that it exists and
isn't empty) before letting the serializer work.
Jun 27 '08 #7
On Wed, 23 Apr 2008 14:52:44 -0700, Michael A. Covington
<lo**@www.covin gtoninnovations .com.for.addres swrote:
[...]
Since the loading and saving are done at different times (at least
minutes
apart) by the same person, I don't see how it could be a race condition.
I don't either. But then, the above is of course a simplification of
what's really going on. It could be that with a concise-but-complete code
sample, an actual problem could be identified. Of course, I suspect that
if you had such a sample and you knew how to get it to misbehave, you
wouldn't be asking the question. :)
Is there some error condition that could result in a zero-length file
(either reading or writing) without throwing an exception?
I should hope not. I admit, I don't know with 100% certainty, but my
approach to an OS API, Windows included, is that it will do exactly what I
tell it to, unless it tells me otherwise. No error implies it completed
the operation I asked for.

The problem has some characteristics of failing to properly flush/close
your output stream, but a) that doesn't explain why the file would show up
with data later on (i.e. when the user goes to email the file to you), and
b) at least in the simplified version you posted, everything appears to be
fine with respect to making sure the output stream is closed.

So I guess I'm out of guesses. Sorry.

One thing you might try is delivering a version of your program with some
instrumentation in it. Have it log user actions, and perhaps also do some
double-checking when the file's written to make sure it winds up the
length you expect (i.e. 0). Heck, you might even write to a
MemoryStream instead, and then do some verification on the length of the
resulting string, as well as making sure that the file written matches the
length and contents of the MemoryStream. That way the file i/o has some
double-checking in it.

Other than that, it's pretty much a mystery to me. :)

Pete
Jun 27 '08 #8
MC
Latest development: The problem seems to be with the program WRITING
zero-length files, not READING them, and earlier, when the customer sent me
"unopenable " files that opened just fine, I'm thinking they were the wrong
files. (Not 100% sure though.)
using (StreamWriter outfile = new StreamWriter(fi lename))
{
XmlSerializer x = new XmlSerializer(t his.GetType());
x.Serialize(out file,this);
outfile.Close() ;
}
Is there any way this could produce a zero-length empty file without
throwing an exception?

Jun 27 '08 #9
"MC" <fo************ **@www.ai.uga.e du.slash.mcwrot e:
>using (StreamWriter outfile = new StreamWriter(fi lename))
{
XmlSerializer x = new XmlSerializer(t his.GetType());
x.Serialize(out file,this);
outfile.Close() ;
}

Is there any way this could produce a zero-length empty file without
throwing an exception?
Is it running on the main GUI thread? If not, and if the *other* thread
doesn't handle exceptions, anything that is thrown may just silently
terminate the thread.

Eq.
Jun 27 '08 #10

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

Similar topics

1
3960
by: Lana | last post by:
Hello all! I need to add another element to an XML file along with its content, but encountered a problem. I tried with the code provided, but it happens so that i can't run the program from my jbuilder. As it has the main method, i dont understand why.. Any help would do. Thanx in advance :) greetings :))
2
7251
by: Jim Witte | last post by:
Hi, How do I set a file input element? If it's a text input, I can set the value property. But this doesn't work with file inputs. And no, I can't change it - I'm writing a script to automate a process on an existing system. Jim Witte jswitte@bloomington.in.us
2
28376
by: Evgeny Zoldin | last post by:
Hi ALL. I need to simulate send POST data ( - file upload) as it was submitted in Browser. In C# I create instanse of IE, navigate to page with the form, fill in the fields and try to Submit by call submitButton.click() Unfortunately it does not work while file_filed.vale = <path_to_file> has no effect, value <INPUT type=file...> cound not be set from script of that HTML page. Is there another way to set that value by means of ..NET ? Below...
2
3432
by: mark | last post by:
How do I detect that a particular form element is a file upload or if the file upload has worked? In the Python cgi module documentation I found suggested code... form = cgi.FieldStorage() fileitem = form if fileitem.file: # It's an uploaded file; count lines
0
830
by: eric.anderson | last post by:
Is there a way to create a file upload element with only server side code?
4
2052
by: rn5a | last post by:
I am storing the physical path of images, along with 3 more columns, in a MS-Access DB table. I want to provide users the option to change this physical image path (as well as the records in the other columns) for which I am using the *File* Form element. The column under which the physical paths are stored is the 4th column in the DB table. Users first come to a page that displays the distinct records existing in column1 in the above...
1
1599
by: Sebarry | last post by:
Hi, I'm using the following code from the-stickman.com to create a file upload list in Javascript. I want to modify it so that the file element is only added if the user has provided a description for the file in a HTML form, but I'm not sure where I need to put the check in. Also it doesn't seem to work in Firefox, only IE, but I can't see what code is not compatible with IE. function MultiSelector( list_target, max ){ 42 43 ...
0
1424
by: sweavo | last post by:
Hi all, (Python 2.5 under cygwin) I'm reading a bunch of XML files and merging them in memory - each file contains a number of packages which are to be merged: for fname in gInfiles: doc=xml.dom.minidom.parse(fname) if gDoc is None:
1
1551
by: Sharad Singh | last post by:
I am new to Javascript/AJAX. I need to upload a file to a server using a file input element(using the 'onchange' event). I need to write a javascript/ajax code for the same. I would be very grateful if someone amongst you might drop a little hint in doing so. Please Help. Thank you.
0
8676
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
9161
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...
0
9029
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8897
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
5860
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4370
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3050
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
2332
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2006
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.