-
-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refitter failed to write generated code: System.IO.IOException: The process cannot access the file 'Generated.cs' because it is being used by another process. #520
Comments
@fabioloreggian Thanks for taking the time to report this Have you tried shutting down the C# build-server? I have run into this a couple of times and this helped when the source generator started acting up
I have not used |
@all-contributors please add @fabioloreggian for bugs |
I've put up a pull request to add @fabioloreggian! 🎉 |
Thanks for the response. I will try updating the build pipelines config to only trigger the build once. Hopefully that will sort out this issue. |
If you use the source generator, you will probably need to build 2x, as the source generator produces actual files that are written to disk post-compilation, so you will need to rerun the build to build the Refit types. The way I do this is that I use |
There is something interesting happening here. I have the following: dotnet restore -> dotnet build. Inbetween the restor and build I run dotnet build-server shutdown. I can see the build server shutting down successfully. However the build step is failing with the same error as before. Also just an FYI the built code is already checked into the repo. (not sure if that makes any difference) |
@fabioloreggian, does this only happen in your CI/CD pipeline and not locally? I mostly use Refitter on projects with a CI/CD pipeline on Azure DevOps using Microsoft-hosted agents running Ubuntu and have no problems. |
Yeah it is only happening in our Azure devops pipeline. It is super strange. Because it is repeatable every time. I did play around with the dotnet commands and the ordering. But nothing really seemed to work. I will do some more investigation tomorrow. |
@fabioloreggian I would like to investigate this further. May I ask what version of .NET you target and what build agent you're using on Azure DevOps? We build, test, package, and deploy everything on |
Describe the bug
Refitter failed to write generated code: System.IO.IOException: The process cannot access the file 'Generated.cs' because it is being used by another process.
When I run the following commands in my build pipeline:
The dotnet restore works as expected, however the dotnet pack fails with the exception above. My assumption is the dotnet restore regenerates the file, doesn't close the stream and when dotnet pack runs, it complains about the file being in use.
I have seen similar behaviour when trying to move the generated source into a different directory in Rider. Where I have to close Rider then move the file and then open Rider again.
Im not sure what is causing the file to still be in use. As File.WriteAllText should release the file immediately after writing. However this is still an issue.
The text was updated successfully, but these errors were encountered: