possible DataSet.ReadXml bug? or maybe just a user error ;)

  • Thread starter Thread starter Tim Mulholland
  • Start date Start date
T

Tim Mulholland

Hopefully someone can point out what is going on here. I'll give a short
explanation first, then a more detailed one at the bottom if anyone wants to
dig into it more.

I have a strongly-typed dataset (from a .xsd file in my project) called
dsConfig.

When i make the following call:

dsConfig.ReadXml("buttons.xml", XmlReadMode.Auto);

i get the following error:

An unhandled exception of type 'System.NullReferenceException' occurred
in Unknown Module.
Additional information: Object reference not set to an instance of an
object.

HOWEVER.

If i change my call to this:

System.IO.FileStream fs = System.IO.File.OpenRead("buttons.xml");
dsConfig.ReadXml(fs, XmlReadMode.Auto);

then it executes properly.

Any ideas? Its not that complicated to do that, but it obviously shouldn't
be that way. More details at the bottom.

Thanks in advance!

Tim

-------------------------------------------------------

OK, so here are the details

I have a usercontrol (we'll call it A). inside of A, there is a function
(we'll call it DoStuff()) that executes the above line of code (the original
one that i said didn't work).
if i have an instance of A in a form, then A.DoStuff() executes with no
problems.

I then have an inherited usercontrol (we'll call it B) that inherits from A.
if i have an instance of B in a form, then B.DoStuff() executes with no
problems.

I then have a separate usercontrol (we'll call it C) that contains an
instance of B. In C, there is a function (we'll call it DoMoreStuff()) that
calls B.DoStuff(). If i have an instance of C on my form, and i call
C.DoMoreStuff(), then i get the error i listed above, and i can fix it only
with the above hack. The error actually occurs all the way down in the code
for A if i include all the projects. in the solution and step all the way
down into it.

Any ideas?

Tim
 
I have an update to my problem.

I checked to see what XmlReadMode the call to ReadXml(fs, XmlReadMode.Auto)
was using (through the return value. It was using XmlReadMode.IgnoreSchema.

Now, if i use

dsConfig.ReadXml("buttons.xml", XmlReadMode.IgnoreSchema);

the line executes fine.

What gives? shouldn't Auto have been choosing this anyway? And even if it
wasn't, why wasn't this error occuring in the base class or the inherited
class, why just when i put the inherited class in a new control?

Thanks in advance,

Tim
 
Back
Top