I have a weird problem in Visual Studio:
if an unhandled exception is thrown during the debugging process I'm not able to build my C# application:
Unable to copy file "C:\Projects\A\bin\A.dll" to "..\..\bin\A.dll".
The process cannot access the file '..\..\bin\A.dll' because it is being used
by another process.
Could not copy "C:\Projects\A\bin\A.dll" to "..\..\bin\A.dll".
Exceeded retry count of 10. Failed.
The file is locked by: "Microsoft Visual Studio 2019 (14904)"
Is there a permanent solution to solve this strange error? (my only workaround is currently to restart Visual Studio)
What I tried and not worked for me:
It's also not practical to insert Pre-build event scripts in all of my projects! Link: https://blog.ndepend.com/visual-studio-script-saves-time-pain/
Does anyone have a solution to this problem?
While working in the server workspace, navigate to the View menu and choose Other Windows, then choose Source Control Explorer. In Source Control Explorer, open the shortcut menu for the folder or file from which you want to remove a lock, and then choose Unlock.
The file might be locked because: The file is shared and another user is currently editing it. An instance of the Office app is running in the background with the file already opened. The file has been marked as Final and can no longer be updated.
Lock a file in C# using File. Lock() method . The lock method let you lock a file so another process cannot access the file. This works even if it has read/write access to the file.
Use Managed Compatibility Mode: Replaces the default debugging engine with a legacy version to enable these scenarios: You are using a . NET language other than C#, Visual Basic, or F# that provides its own Expression Evaluator (this includes C++/CLI).
What worked for me - Close the Solution, Delete the bin and obj folder, re-open and build.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With