I am attempting to download pdf files from URLs. The files will automatically download upon clicking, or entering the URL. Unfortunately, I am unable to share the specific links due to client security & privacy; however, I have confirmed that the links work when individually entered into the Download File from URL activity.
Problem:
The problem arises when I attempt to loop through the list using a For Each activity with the Download File from URL activity in the Body section of the loop. The first URL will successfully download, but when it comes time to download the second file, I am met with the following error:
Download File from URL: Cannot access a disposed object. Object name: 'System.Net.Http.HttpClient'.
Sequence Structure:
I have attached a screenshot of the sequence below (this is part of a much larger workflow, but when I was troubleshooting I noticed it still threw the error at the smallest level so I figured for simplicity this would suffice)
Introduce a little delay inside the loop and check..generally this error occurs when a disposed object is being used again or in asynchronous runs..so adding a delay might suffice
Alternately try to move the output file somewhere so that the link is broken
Try to include some activities before and after download activity.
Before:
Add log message activity to print the current value of the file that’s going to be downloaded.
After:
Use file exists activity to check whether file has been downloaded or not? If yes, print log message stating file has been downloaded successfully.
Such steps also aid in troubleshooting. If still doesn’t work, induce a delay specifically in between downloads.
Hey @Anil_G, I appreciate you taking the time to respond! I tried adding in the delay (set for 2 seconds) and it did not work. I added in the Move File activity and it did not work either. I also tried a combination of the two activities, and that also did not work…
I ran the process through a Python script in VS Code and it worked so I might end up creating a Python Scope sequence, but it’s annoying to have to essentially restart from there after working on this project for a few weeks.
Hi @sonaliaggarwal47, I appreciate your response!! I have this activity in a much longer sequence, but I figured for simplicity breaking out in the smallest section possible could be beneficial. However, I stand corrected! I tried Anil’s (and your) suggestions and the error persists. If you think a full screen shot of the sequence would be beneficial please let me know and I’ll see what I can do. I can also upload the Output logs if you those would be of assistance.
@Jsorey04 A walkaround I could think of is to add retry scope to download file from URL activity. Lets keep number of retry to 5 and interval to 5 or 10 seconds. Can you try this If its helpful ?
Whenever this exception occurs, bot would catch the exception, and in catch block, there will be download file from url activity which would try to download the item again.
@sonaliaggarwal47
As with Darshan’s suggestion, this was one of my previous troubleshooting items on Friday before posting. This time for the Catch I tried all the following methods (since there there is no System.Net.Http.HttpClient catch)
Hey @postwick, thank you for joining this conundrum. I thought your recommendation was just going to keep the process waiting indefinitely; however, interestingly enough it still ends up throwing the error.
@Jsorey04 In debug mode it will stop the process when error encounter you have to click on continue to run the process as it will retry to download the file. Like wise it will retry. Can you try this?