6

I have an asp.net core project that references .NET Framework and I'm using Visual Studio 2017 Enterprise. When I try to build my solution, I came across with this error:

Unable to copy file "obj\Debug\net461\MyProject.exe" to "bin\Debug\net461\MyProject.exe". 
Access to the path 'bin\Debug\net461\MyProject.exe' is denied.

Even if I cleaned the solution and build again, I still have this error.

Anyone faced this error?

Tiago Ávila
  • 2,737
  • 1
  • 31
  • 34

4 Answers4

7

Go to Task Manager and look for Microsoftvshost.exe and kill them all. Even though you stop debugging the exe can continue to run in the background. This causes a lock on the file.

Ottak
  • 293
  • 1
  • 6
  • Thanks for your help @Ottak. I also had to close my antivirus for a while, it looked like it was holding that file. – Tiago Ávila Jul 28 '17 at 19:03
1

Close the application and delete Obj and bin folder

0

First, make sure you have the .net core localhost server stopped, before trying to build the solution.

dezox
  • 146
  • 9
0

I have seen this error before. Trying the following has worked for me:

1. Close the current solution.
2. Close Visual Studio.
3. Start Visual Studio in Administrator mode.
4. Re-open and build the solution.

The above can avoid the common copy file and file Access Denied errors.

Andrew Halil
  • 1,195
  • 15
  • 15
  • 21