views:

90

answers:

1

I'm trying to read a XmlReader into a XDocument

//GetContentStructureReader() retrieves the reader from an external source
XmlReader reader = GetContentStructureReader();
XDocument.Load(reader);

I keep getting the following exception with one specific data source:

System.ArgumentNullException was unhandled by user code Message=Value cannot be null. Parameter name: value Source=System.Xml.Linq ParamName=value StackTrace: at System.Xml.Linq.XAttribute..ctor(XName name, Object value) at System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r) at System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r, LoadOptions o) at System.Xml.Linq.XDocument.Load(XmlReader reader, LoadOptions options) at System.Xml.Linq.XDocument.Load(XmlReader reader)

So it seems that during the loading, at some point a XAttribute is being initialized with null value.

What is a null attribute in XML? I've tried examining the (6 megabyte) source document to correct the data, but in vain, since I don't know what kind of XML construct I'm looking for.

Is there a workaround for this?

A: 

During loading of a document null value should not appear as values for XAttribute. So what you're seeing is unexpected. You could stop on the exception in the debugger to see the callstack and the values of the parameters (the XName name in particular) which might help you locating the attribute in the source document. (You could also try ((IXmlLineInfo)reader) in your whatch window on one of the frames which do have the reader defined. In any case the default implementation of XmlReader in the .NET Framework should never cause this. So the question is, where/how did you create the instance of the XmlReader object you pass to the Load method?

Vitek Karas MSFT
Moved on from this problem and attacked it in another way. I couldn't attach a debugger to the line of code, because the XmlReader was being created inside a third-party library. Accepting this because the advise on debugging is solid. Thanks!
fencliff