tags:

views:

31

answers:

2
+2  A: 

Well, it sounds like it simply isn't a valid XML file.

If you print out the result of sr.ReadToEnd() instead of calling XElement.Load, what does it look like? If you try to load the file into an XML editor, what happens?

Btw, it's better to use a using statement than calling Dispose explicitly: with your current code, the StreamReader isn't disposed if Load throws an exception.

Finally, is there any reason you're not just using XElement.Load(documentationFileLocation)?

Jon Skeet
I am doing - Console.WriteLine(sr.ReadToEnd()) and I am getting empty screen,And I checked twice that the file exists at documentationFileLocation.And I deleted StreamReader and added XElement.Load(documentationFileLocation) and still getting the problem,And I didn`t have a special reason to use StreamReader
Yosy
@Yosy: Well, it certainly sounds like an empty file. Did you try loading the file into an XML editor?
Jon Skeet
Yes,Tried using notepad and Visual C# Express 2010,Here is the xml file contents - http://pastebin.com/YTTS6vcf
Yosy
+1  A: 

Have you tried XDocument.Load() instead of using XElement? If the file begins with an XML declaration <?xml ..., you might get this error when trying to load an element from it.

Edit: the file you pasted on pastebin has no encoding specified. Can you try to open this file in notepad and re-save it as ANSI, the see if it loads? Just to make sure that we don't have an encoding or BOM problem.

Lucero
Tried using XDocument.Load() and still getting this error,and yes the file starts with "<?xml version="1.0"?><doc>"
Yosy
The problem is that this file is automatically generated by visual studio ( Project Properties -> Build -> XML Documentation file)
Yosy
Yes, I know. But as I wrote, this is to diagnose the issue, so that we know how to proceed...
Lucero
The same error,I think that I will be saved without BOM because Visual Studio Regenerate this file every build that I am doing.
Yosy
I downloaded the pastebin and I can load it with `XDocument` just fine! So there is something else which is wrong somehow...
Lucero
Tried again - Console.WriteLine(sr.ReadToEnd()) using StreamReader with encoding of Encoding.UTF8 and I get the xml file content but with XElement of XDocument I am getting this error!!!
Yosy
So do a `XDocument.Parse(sr.ReadToEnd())` - does that work?
Lucero
It really hates me =X "XDocument document = XDocument.Parse(sr.ReadToEnd()); " The same error =X
Yosy
Worked :) Just Changed other line of code from document.Elements("member") to document.Element("members").Elements("member")
Yosy