Groups | Blog | Home
all groups > dotnet xml > june 2004 >

dotnet xml : System.NullReferenceException during XML Deserialization


David B. Bitton
6/14/2004 3:40:52 PM
I'm experiencing odd behavior on the part of the XMLSerializer. I'm
deserializing an XmlNode. The XmlNode is pass as part of a call to
IConfigurationSectionHandler.Create. My XML looks like:

<sectionName>
<settings>
...
...
...
</settings>
</sectionName>

I have define my class as such:

[XmlRoot(Namespace="", IsNullable=false, ElementName="settings")]
public class MyAppSettings
{
....
}

I am passing my XmlNode to the XmlSerializer like so:

return serializer.Deserialize( new XmlNodeReader( section.ChildNodes[0] ) );

What happens is I get an System.NullReferenceException eminating from the
System.Xml.Serialization.XmlSerializationReader.UnknownNode() routine which
is being called by the dynamically created derivative XmlSerializationReader
code. I can see this in the stack trace.

Perhaps someone can shed some light on this?




--
--

David B. Bitton
david@codenoevil.com
www.codenoevil.com

Code Made Fresh DailyT

Christoph Schittko [MVP]
6/15/2004 9:47:08 AM
David,

Can you take a look at my troubleshooting article on MSDN and let me know if
that helped diagnosing the problem?


--
HTH
Christoph Schittko [MVP]
Software Architect, .NET Mentor

[0]
http://msdn.microsoft.com/xml/default.aspx?pull=/library/en-us/dnxmlnet/html/trblshtxsd.asp


[quoted text, click to view]

David B. Bitton
6/15/2004 11:17:18 AM
Chris,
I'll take a look at the site, but before I do, let me tell you about
what I did to get it to work. Once I removed all of the whitespace in the
XML, then it was OK. Basically, i changed it to:

<sectionName><settings>...</settings></sectionName>

and magically it started to work. One thing I noticed is that when I looked
at the XmlNodeReader in the cmd window, after I called Read() once, the
value was "\t\t\r\n\" which obviously is a whitespace node. Looks like that
was what the dynamic code was attempting to interpret.

--
--

David B. Bitton
david@codenoevil.com
www.codenoevil.com

Code Made Fresh Daily™
"Christoph Schittko [MVP]" <christophdotnetINVALID@austin.rr.com> wrote in
message news:%23f0RjeuUEHA.3076@TK2MSFTNGP10.phx.gbl...
[quoted text, click to view]

David B. Bitton
6/16/2004 4:13:42 PM
Chris,
I read the page and I don;t see anything that'll help. Like I said, if
I delete all of the whitespace between elements and have the XML all on one
line, it works just fine. This is both weird and annoying.

--
--

David B. Bitton
david@codenoevil.com
www.codenoevil.com

Code Made Fresh Daily™
"Christoph Schittko [MVP]" <christophdotnetINVALID@austin.rr.com> wrote in
message news:%23f0RjeuUEHA.3076@TK2MSFTNGP10.phx.gbl...
[quoted text, click to view]

David B. Bitton
6/16/2004 4:51:15 PM
As even more clarification, I installed my code on another machine and I
received the same error.

--
--

David B. Bitton
david@codenoevil.com
www.codenoevil.com

Code Made Fresh Daily™
"Christoph Schittko [MVP]" <christophdotnetINVALID@austin.rr.com> wrote in
message news:%23f0RjeuUEHA.3076@TK2MSFTNGP10.phx.gbl...
[quoted text, click to view]

Dennis Redfield
6/17/2004 12:48:54 PM
david,
could we see the actual XML file and its schema?
thanks.
dlr
[quoted text, click to view]

David B. Bitton
6/17/2004 1:04:45 PM
Dennis,
I've determined that the problem lies with ConfigXmlElement (which is a
internal class of ConfigXmlDocument). I started a new thread,
ConfigXmlDocument Handles Whitespace Improperly. I detailed what I've found
so far and how it causes XmlSerializer to fail.
--
--

David B. Bitton
david@codenoevil.com
www.codenoevil.com

Code Made Fresh Daily™
[quoted text, click to view]

AddThis Social Bookmark Button