question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Frequent "file being used by another process IOException" when building documentation

See original GitHub issue

Hi, I maintain https://github.com/microsoft/FactoryOrchestrator, which uses DefaultDocumentation to generate markdown files.

When building both locally and in ADO I frequently hit “Unhandled Exception: System.AggregateException: One or more errors occurred. —> System.Exception: Error while writing documentation for Microsoft.FactoryOrchestrator.Core —> System.IO.IOException: The process cannot access the file ‘D:\FactoryOrchestrator\bin\DefaultDocumentation\CoreLibrary\Microsoft-FactoryOrchestrator-Core.md’ because it is being used by another process.”

By adding basic retry logic I am able to work around the issue, but I couldn’t figure out the root cause of the exception, all threads are writing different files at the time of the exception.

A dump captured from running the debug version of your tool (0.6.13) I built locally is at https://1drv.ms/u/s!AigADXVMXV_6t8ML930SnhDu6vxfog?e=xOd4uQ

You might also be able to repro by checking out and building https://github.com/microsoft/FactoryOrchestrator

The retry logic I added (EDIT, one retry works fine in debug, but not for release, updated to 10 retries):

        public void WriteDocumentation(string outputFolderPath, int retryIOException = 0)
        {
            _docItems.Values.Where(i => i.GeneratePage).AsParallel().ForAll(i =>
            {
                try
                {
                    using DocumentationWriter writer = new DocumentationWriter(_fileNameMode, _nestedTypeVisibility, _wikiLinks, _docItems, _links, outputFolderPath, i);
                    i.WriteDocumentation(writer);
                    
                }
                catch (Exception exception)
                {
                    if (retryIOException < 10 && exception is System.IO.IOException)
                    {
                        // Retry up to 10 times on IOException
                        WriteDocumentation(outputFolderPath, ++retryIOException);
                    }
                    else
                    {
                        throw new Exception($"Error while writing documentation for {i.FullName}", exception);
                    }
                }
            });
        }

While I would love to root cause this and get a real fix, maybe adding this logic or something similar in the interm might help me and any others who hit this?

Removing AsParallel().ForAll and using a serial foreach also resolves the issue.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
spaceisfuncommented, Mar 24, 2021

I really appreciate you addressing this so quickly @Doraku !

Thanks for writing such a useful piece of OSS, this was the best doc generator out of the (admittedly only a handful of) ones I tried 😃, and your prompt resolution here only helps confirm that 🥇 .

0reactions
Dorakucommented, Mar 23, 2021

I can’t reproduce it but I have a fairly old cpu, so maybe there’s something wrong with the file system when trying to write too many files at the same time 😕 I took your word for it and removed the parallel execution, premature optimization probably biting me in the ass eh. As you said it didn’t do much 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

IOException: The process cannot access the file 'file path ...
The error indicates another process is trying to access the file. Maybe you or someone else has it open while you are attempting...
Read more >
Builds failing with "The process cannot access the file ...
Cause. The " The process cannot access the file because it is being used by another process " error indicates that there is...
Read more >
Process cannot access the file because it is being used by ...
This is a well known problem with PictureBox (actually by the Bitmap constructor). See this SO answer for a workaround:
Read more >
Xamarin build error. File in use by another process.
The "LinkAssemblies" task failed unexpectedly. System.IO.IOException: The process cannot access the file 'C:\Work\lexacom\Lexacom.Mahon.Xamarin.
Read more >
Bug - Error: The process cannot access the file because it ...
Bug Error: The process cannot access the file because it is being used by another process.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found