How to fix the error "Could not Copy %personalspace/obj/Debug/net6.0/apphost.exe to /bin/Debug/net6.0/my.exe"

GOEL Kohima 5 Reputation points
2023-09-06T13:02:27.36+00:00
  1. Created my console application (.Net6.0) and debugging on the same on VS2022 multiple times.
  2. Now after few runs start getting below errors: Error 1: Severity Code Description Project File Line Suppression State Error MSB3027 Could not copy "C:\Users\userid\personal Data\asyncprogramming\asyncprogramming\asyncprogramming\obj\Debug\net6.0\apphost.exe" to "bin\Debug\net6.0\asyncprogramming.exe". Exceeded retry count of 10. Failed. The file is locked by: "asyncprogramming (60996)" asyncprogramming C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets 5097
  3. Error 2: Severity Code Description Project File Line Suppression State Error MSB3021 Unable to copy file "C:\Users\userid\Documents\personal Data\asyncprogramming\asyncprogramming\asyncprogramming\obj\Debug\net6.0\apphost.exe" to "bin\Debug\net6.0\asyncprogramming.exe". The process cannot access the file 'bin\Debug\net6.0\asyncprogramming.exe' because it is being used by another process. asyncprogramming C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets 5097
  4. After restarting my machine, visual studio nothing helped and getting same error.
  5. Created altogether new application starting getting the same error again.
  6. So to fix locally updated the application version to .Net5.0 and debug in Visual Studio 2019 and strangely started working successfully.
  7. So , I doubt may be there is some bug in Visual Studio 2022.
Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
5,049 questions
{count} vote

1 answer

Sort by: Most helpful
  1. Anna Xiu-MSFT 28,661 Reputation points Microsoft Vendor
    2023-09-07T08:31:39.32+00:00

    Hi @COEL Kohima, 

    Welcome to Microsoft Q&A! 

    For error MSB3027 and MSB3021, common causes include the file is locked by another process, insufficient permissions to write to “bin\Debug\net6.0\asyncprogramming.exe”, insufficient space on the drive. 

    Are you using the latest version of VS2022 17.7.3? If no, please update your VS2022 to the latest version and try again.

    I created a Console App C# (.NET 6.0) and it builds successfully. Have you tried to create a .NET 7.0 project? 

    If it only occurs in .NET 6.0 project, I suspect the .NET 6.0 target framework is corrupted. You can consider to reinstall the .NET 6.0. 

    Otherwise, you can repair VS2022 and run it as administrator to try again. 

    Sincerely,

    Anna


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". 
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

     

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.