0

I am parsing XML in a dataset it works fine except with some RSSs it gives an error:

Object reference not set to an instance of an object.

I tried the XmlDataSource and it gives the same error Note that there isn't any differences between the RSSs files and i don't know on what base it gives such error

Cœur
  • 37,241
  • 25
  • 195
  • 267
Miroo
  • 795
  • 3
  • 13
  • 35
  • 1
    SHow us the XML you're trying to parse, and the parsing code! We're not mind-readers, you know... we need to see what you're trying to do.... – marc_s Dec 12 '10 at 13:41

1 Answers1

0

Without your code it's impossible to say exactly where the error is.

However, when you use a reference type, you should check that it is not a null reference. That essentially means everywhere you use a period (as in "someVariable.DoSomething()"), you should have verified that the variable is not null:

So, this code is dangerous:

SomeType someVariable = xmlElement.Nodes[0];
someVariable.DoSomething();

because someVariable may be null.

To fix this, you need to check if it is safe to use it, like this:

SomeType someVariable = xmlElement.Nodes[0];
if (someVariable != null)
    someVariable.DoSomething();

So look through your code, and look at all the places where you use a reference without checking if it is null.

Jason Williams
  • 56,972
  • 11
  • 108
  • 137