Foreach error in document understanding

I am getting files from a folder using “Directory.GetFiles(path)” in foreach.

image

picking invoices one by one and process them in document understanding to read required data. it is working fine for one file. but when processing multiple invoices then it is processing one less from total count, I mean if 5 files in folder then process 4 successfully and getting error for last.

“Object reference not set to an instance of an object.”
image

Please help me.

Can you show us more of the workflow? What is going on inside the For Each body?

I have changed the foreach to while loop to fix the problem. its working now but not worked with foreach.

can you tell me how you solved using while loop ? I am facing similar issue!!!

Hi @neethulg , I have done below step to resolve my issue,

  1. Assign Directory.GetFiles(path) to string array before while loop.
    image

  2. Add While loop on count/length of that string array. [filesIndex variable is declared to check index of While loop.]
    image

  3. Get new item from string array at start of loop.
    image

  4. Do required operations in loop and at the end increment filesIndex by 1.
    image

These steps helped me to get rid of fereach to process Document Understanding.

hope you will find your solution also.

ping me if you need anything else.

Regards,
Hamid Hassan

Thank you Hamid for the help. I used while loop and counter to pick the files. Now it is working for ma as well. :slight_smile:

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