Process cannot access file because its already being used

I am getting the following error. However, It doesn’t make much sense because it worked perfectly yesterday and every day before and is now throwing this error. Nothing has been changed in the code or file paths between runs. Can someone help? I can’t figure out why it randomly cannot access it.

21.10.7+Branch.support-v21.10.Sha.4fc9759469a976c6aff9aff581b459a31fa01cd9

Source: Log Failed Closing All Applications

Message: One or more errors occurred.

Exception Type: System.AggregateException

RemoteException wrapping System.AggregateException: One or more errors occurred. —> RemoteException wrapping System.IO.IOException: The process cannot access the file ‘D:\Bot_Logs\CloserBot\20221116\072337_Log_CloseOutPerformer_CON_EXPIRED_20221116_072337.txt’ because it is being used by another process.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.FileStream…ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.StreamWriter.CreateFile(String path, Boolean append, Boolean checkHost)
at System.IO.StreamWriter…ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize, Boolean checkHost)
at System.IO.StreamWriter…ctor(String path, Boolean append, Encoding encoding)
at System.IO.File.InternalAppendAllText(String path, String contents, Encoding encoding)
at System.IO.File.AppendAllText(String path, String contents, Encoding encoding)
at UiPath.Core.Activities.AppendLine.<>c__DisplayClass21_0.b__0()
at UiPath.Core.Activities.Retry.<>c__DisplayClass1_0.b__0()
at UiPath.Core.Activities.Retry.Do[ResultType](Func1 action, Int32 timeoutMS, Int32 retryCount) --- End of inner exception stack trace --- at UiPath.Core.Activities.TaskAsyncCodeActivity1.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

HI @kasey.betts

Can you check if the file is opened in the machine or user

Have you tried with Kill process activity

Regards
Gokul

The file is not open anywhere else. Kill which process? The txt file (so notepad)?

image

That does not work either

Oh it actually works if I move the activity to be done earlier.

Do you know why it might randomly start doing that when it wasn’t giving this error before?

Great @kasey.betts

I don’t have any idea, Basically this error occur we have use Kill process. In the back ground may be the file is processing I’m not sure about your process scenario.

Regards
Gokul

So it worked a couple times but now it is back to throwing the same error even with the kill process activity

After Kill Process activity Use Delay activity set the Delay time as 00:00:05 and try it.

Can you share the workflow screenshot @kasey.betts