How to handle Object reference not set to an instance of an object

Does anyone know why I can’t extract the value of the customerID, from the XML?
In the past I did the same thing and I succeeded.

I have the XML in the XmlOutputDoc and I use :

XmlOutputDoc.Element(“export”).Element(“batchid”).Element(“customer”).Element(“header”).Element(“customerID”).Value

This is the value of XmlOutputDoc

image

Hi @mironb

when you try to use an object that has not been initialized.

To avoid this error, you can choose to check for the null and provide a default value.

You can also explicitly check for null from method calls and throw a custom exception

Check out this thread

Regards
Gokul

Hi @mironb Can you share that sample XML input file

Hi @Gokul001
But debug it and you can see that there is no value that is initialized to NULL
I have attached a screenshot

hi @ushu

Can you also share the expression that you have written in the write line activity

@ushu

XmlOutputDoc.Element(“export”).Element(“batchid”).Element(“customer”).Element(“header”).Element(“customerID”).Value

@mironb can you please do one quick test. Try to print batch id value

XmlOutputDoc.Element(“export”).Element(“batchid”).Value

This it to identify, is XmlOutputDoc is empty or is it something wrong with the exp

@ushu
This is the XmlOutputDoc :

image

As I mentioned you can see the in the post every value is not null

@mironb

If you observe the structure of xml customer tag is under export but not under the batch id tag…that is the reason its failing …you have to use like this

XmlOutputDoc.Element(“export”).Element(“customer”).Element(“header”).Element(“customerID”).Value

Cheers

@ushu

Its print the number

@Anil_G

Thanks

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.