Exception Object reference not set to an instance of an object

Hi @sereganator,

What variable type is areaKVOKS?

Try areaKVOKS = "" in the if statement

XElement.
If the tag is absent, then assign an empty value to the areaKVOKS variable and write it through add data row, if not empty, then write the extracted value. How to do it?
teg area

Hi @sereganator,

You would want a log message or message box on the Then side of the if statement to show the value of areaKVOKS. You may need to specify .toString after it but I’m not sure.

On the right, you would have your assign as shown in the screenshot you’ve attached.

Below the if statement goes your add data row, to add the areaKVOKS variable to a datatable. I’m not sure about your datatable structure so I will leave that up to you to do.

Doesn’t work, writes the error “Object reference not set to an instance of an object”.

Hi @sereganator,

Forgive me, remove the variable from the log message. It wouldn’t work because the variable is null and we had already established that.

But now there is an error in add data row (“Object reference not set to an instance of an object”.) as we are trying to add a tag that is not there. How do I set areaKVOKS (data type XElement) to an empty value?

The variable areaKVOKS is already an empty value, hence why you’re getting your exception message. You can’t output the variable, so in your log message you need to put this:

"Variable areaKVOKS is an empty value"

Or something similar

Add data row process with Try Catch?

You could try that, and hn the Catch section you could add a log message to say what the exception was. This would just be the variable exception

@sereganator
have a check on a different approach:

lets keep the returned Null to make clear, that the element was not found
for a defensive access use following:
Assign activity:
left side: yourValueReceiveVar
right side:
if(isNothing(yourXElementVar), “ValueNotFound”, yourXElementVar.Value.toString)

The more important question to clear is about:

  • was it not found as it exists not OR due an bug in the retreival statement
1 Like

That is how it should be?
The data type of areaReceive String.
As before, there was an error in the Add data row.

try it. Waht the result?

error in add data row “Object reference not set to an instance of an object”.

what is the answer to the from quote: can it be the case taht the element is missed in some cases or not?
o

In some xml files the Area tag is missing. Empty values ​​in the tag reads normally.

can you share your xaml, so I can do some checks? thanks

Sure
Main.xaml (41.2 KB)

@sereganator
check your add datarows. ensure the correct variables are used (e.g. the defensive ReceiveValueVar)

Thanks a lot, it works.

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