Files being locked by UiPath.Executor

Hi All,

We are currently facing an issue with a project that has been running smoothly for the past two years. Recently, we started encountering the error:

“The process cannot access the file because it is being used by another process.”

This error occurs when the process tries to replace content in a Word document, which happens approximately 30 times during execution. After some investigation, we identified that the issue seems to be caused by the UiPath.Executor locking the file by a handle that is not released properly.

We attempted to resolve this by using a simple “Kill Process” activity, but it didn’t help. We also tried implementing the following code snippet to force garbage collection, but unfortunately, it didn’t resolve the issue either:

System.GC.Collect();
System.GC.WaitForPendingFinalizers();
System.GC.Collect();
System.GC.WaitForPendingFinalizers();

Has anyone experienced similar behavior? If so, what solutions or workarounds worked for you?

Thanks in advance for your help!

By the way: we use 2023.10 and the project is in Windows-Legacy and classic design

If you are using Word Application Scope many times, Word stays open in memory.

Set Properties in Word Application Scope → CloseWord = True

You can also specifically kill using Kill Process → “WINWORD”. These you can try , it should work.

If you still face issues, try converting it to modern design , since locking is handled in modern.

Hi Mohammed,

We are not using the Word Application Scope. We only use the seperate “Replace Word” activities. We already are using several “kill WINWORD” activities.

I guess that will be the next thing to do, but as for now we are looking for a fast solution.

I understand you are using Kill WINWORD

This will work only if Word is open—but not if UiPath.Executor is locking the file.
Also we cannot ask UiPath to close its own executor, hope this makes sense.

Are you considering to migrate to modern ?

We are planning to migrate it to modern, but as I said, for the moment we need a fast solution since it’s a productive process running and helping business daily. Migration will take some time and is not done withing a week.

If you want a fast solution Use Vb.Net FileStream Instead of Word Activities, try this workaround. This will bypass Word completely.

Dim text = File.ReadAllText(filePath)
text = text.Replace(“old”,“new”)
File.WriteAllText(filePath, text)

Give this a try