System.NullReferenceException in XmlDocument.Load()

G

Guest

Hi,

I have a strange error that occurs on loading an XML document:
The code is:

// create a document
XmlDocument myDoc = new XmlDocument();
// and load it from file
myDoc.Load(filename);

Inside of .Load()I am getting a System.NullReferenceException in about 1 out
of 10 runs (always the same xml file).

If the exception occurs, the stack seems to be corrupt since I can not see
the callstack but interesting enough a second thread (my app is single
threaded) which seems the cause of the exception.

Is this a known bug or issue?

I am using .NET Framework 1.1 under Visual Studio 2003.

thanks
doc
 
K

knowdotnet

how do u specify the file name. i mean full path or relative path and
is there any other file access in the same code.
 
G

Guest

knowdotnet said:
how do u specify the file name. i mean full path or relative path and
is there any other file access in the same code.

It is a string, name only, in the same directory.
The app is not very complex.
It is just always the same, but sometimes it just crashes.

The XML file itself is always the same.

But it crashes sometimes.

doc
 
K

Kevin Yu [MSFT]

Hi,

I tried it on my machine, but I cannot reproduce it. If you simplify your
code to just these 2 lines, does this also happens with the same xml file?

XmlDocument myDoc = new XmlDocument();
myDoc.Load(filename);

Kevin Yu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
G

Guest

Kevin Yu said:
Hi,

I tried it on my machine, but I cannot reproduce it. If you simplify your
code to just these 2 lines, does this also happens with the same xml file?

XmlDocument myDoc = new XmlDocument();
myDoc.Load(filename);

Yes, it is the same file all the time. The actual code that runs before is
instantiation of some classes, which are totally simple, nothing unmanaged or
so.

The crash does not happen all the time, but maybe it is connected to the
fact I am running it in the debugger. It is only 1 out of 10 in average.

I wrote a set of classes to decode DICOM images and packed it into an
Windows Forms application. I actually do run in an onClick() function of the
form.

First I use a Fileselector to select the file to read, then the a new Class
gets instanced. The first thing it does is reading an XML file which
describes the Data Dictionary.

I can pass you the whole code, but I am pretty sure that there is no magic
that could corrupt the memory or so before that runs.

The machine itself is totally stable.

Thanks so far,

doc
 
K

Kevin Yu [MSFT]

Hi doc,

I understand this issue. I might not be very clear in my last post. We're
trying to narrow down this issue. In my last post, I suggested you put into
a smaller sample with only two lines of code.

XmlDocument myDoc = new XmlDocument();
myDoc.Load(@"c:\aaa.xml");

Please hardcode the file name and path to this sample. Run this sample in
debugger as you ran you app to see whether the NullReferenceException is
thrown again. Please try this and let me know the result. So I can provide
my further steps to help.

Kevin Yu
Microsoft Online Community Support
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
K

Kevin Yu [MSFT]

Hi doc,

I'd like to know if this issue has been resolved yet. Is there anything
that I can help. I'm still monitoring on it. If you have any questions,
please feel free to post them in the community.

Kevin Yu
Microsoft Online Community Support
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
G

Guest

Kevin Yu said:
Hi doc,

I'd like to know if this issue has been resolved yet. Is there anything
that I can help. I'm still monitoring on it. If you have any questions,
please feel free to post them in the community.

Hi Kevin,

not solved yet.

I didn't get the message that you responded, I will try that and let you
know the result. I can also offer you to pass you the complete source and XML
file.

best
doc
 
K

Kevin Yu [MSFT]

Hi doc,

In case of you didn't received my last post:

You can try to use a very simple project with only 2 lines of code.

XmlDocument myDoc = new XmlDocument();
myDoc.Load(@"c:\aaa.xml");

Run this project several times to see if the same exception is thown.
Please let me know the results, and we can make further troubleshooting.

Kevin Yu
Microsoft Online Community Support
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
K

Kevin Yu [MSFT]

Hi doc,

Have you reproduced this error with simplified code?

Kevin Yu
Microsoft Online Community Support
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
G

Guest

Hi Kevin,

Kevin Yu said:
Have you reproduced this error with simplified code?

It did not come up with this variant, unfortunately I am currently bound to
another project.

I am wondering if it is possible to still corrupt the memory heap in a
managed app, because it only seems to happen when I am debugging, never had
it when using the release version of it.

I will investigate a bit more when I am back on that project, for now I can
not replicate it anymore, so we might close this for now, I will repost when
I comes up again and I found something out.

Thanks for your help and support,

Doc
 
K

Kevin Yu [MSFT]

No problem. When you come back to this issue, please repost in the
commnity. Thank you!

Kevin Yu
Microsoft Online Community Support
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
D

DaanishRumani

Is the file in the same folder as the EXE or that same folder as the
Source File!!!!!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top