@harsha1123 - When you run the Main.xaml, please make sure that the file “syntel letter pad.jpg” is not open in your laptop/desktop. This error comes up when your process is trying to access the file which is already open.
img.Dispose(), even set img=Nothing and load another image does not help
Strangely but it works fine in debug mode (F7).
When I run same code (F5) it throws exception on deleting image file. Delay doesn’t help.
Here you can get example, and video.
I simplified code as much as possible, but bypassing error in debug mode very unstable and this code can throw exception with every little edit (even if I put OCR outside of additional sequnce).
Looks like every use of image make a lock for image file: if I delete OCR - it works fine even I run code, not only in debug.
Uh… Yeah, I resolved the problem same way, using GC.Collect, thanks to UiPath tech support.
Just completely forgot about this topic.
Just one note, I made some research and it seems that in most cases GC.Collect is enough for release image file.
GC.WaitForPendingFinalizers in general is rather slow and in some cases may cause dead lock so it’s recommeneded not to use it if it’s not necessary.