I can't get a screenshot of error pic in try catch

This is what error comes

System.ComponentModel.Win32Exception (0x80004005): The handle is invalid
at System.Drawing.Graphics.CopyFromScreen(Int32 sourceX, Int32 sourceY, Int32 destinationX, Int32 destinationY, Size blockRegionSize, CopyPixelOperation copyPixelOperation)
at System.Drawing.Graphics.CopyFromScreen(Point upperLeftSource, Point upperLeftDestination, Size blockRegionSize, CopyPixelOperation copyPixelOperation)
at UiPath.Vision.UiImage.FromScreenRegion(Rectangle region)
at UiPath.Core.Image…ctor(Region screenRegion)

UiPath.Core.ImageOperationException: System.ComponentModel.Win32Exception (0x80004005): The handle is invalid
at System.Drawing.Graphics.CopyFromScreen(Int32 sourceX, Int32 sourceY, Int32 destinationX, Int32 destinationY, Size blockRegionSize, CopyPixelOperation copyPixelOperation)
at System.Drawing.Graphics.CopyFromScreen(Point upperLeftSource, Point upperLeftDestination, Size blockRegionSize, CopyPixelOperation copyPixelOperation)
at UiPath.Vision.UiImage.FromScreenRegion(Rectangle region)
at UiPath.Core.Image…ctor(Region screenRegion) —> System.ComponentModel.Win32Exception: The handle is invalid at System.Drawing.Graphics.CopyFromScreen(Int32 sourceX, Int32 sourceY, Int32 destinationX, Int32 destinationY, Size blockRegionSize, CopyPixelOperation copyPixelOperation)
at System.Drawing.Graphics.CopyFromScreen(Point upperLeftSource, Point upperLeftDestination, Size blockRegionSize, CopyPixelOperation copyPixelOperation)
at UiPath.Vision.UiImage.FromScreenRegion(Rectangle region)
at UiPath.Core.Image…ctor(Region screenRegion)
— End of inner exception stack trace —
at UiPath.Core.Activities.ObsoleteTaskAsyncCodeActivity`1.EndExecute(AsyncCodeActivityContext context, IAsyncResult result)
at System.Activities.AsyncCodeActivity.System.Activities.IAsyncCodeActivity.FinishExecution(AsyncCodeActivityContext context, IAsyncResult result)
at System.Activities.AsyncCodeActivity.CompleteAsyncCodeActivityData.CompleteAsyncCodeActivityWorkItem.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)

@Sathish_Sathish1,

What’s the code logic you are using?

Thanks,
Ashok :slight_smile:

Hi Sathish,

This error can occur due to various reasons.

  1. If you’re using multiple monitors or unusual display configurations, it’s possible that the coordinates or handle being used to capture the screen are invalid. Ensure that the coordinates are within the bounds of the available screens.
  2. Sometimes attempting to capture a screenshot too quickly after a screen transition or window resize can result with this error. Try adding a delay or retry mechanism.
  3. Insufficient system resources may cause this. It may be a one-time error caused by system issues. You can try restarting the machine.

Please let me know if any of these solutions help.

Best Regards,
Kardelen

1 Like

Hi @Sathish_Sathish1

Please let us know if this error is coming when you are taking screenshot via VM machine ?

If it is VM then try to follow this link :

I hope this might give you an rough idea .
Hope it helps.

Regards

1 Like

this error comes in try catch like in try block i used to download report from site and in catch block i kept to get a take screen shot of error pic and share that screenshot in mail

  1. im using only one production server
  2. i may add some delay and try it or will try retry mechanism
  3. we cant do that because process are running server but may try it
1 Like