Juw
Juw

Reputation: 2089

Visual Studio locked file

I use the latest Visual Studio Community 2017 (15.4). And since i installed Visual Studio (never worked in it before). I have ALWAYS despite version had this issue. After compiling a couple of times i start to see:

Unable to copy file "obj\Debug\afile.exe" to "bin\Debug\afile.exe". The process cannot access the file 'bin\Debug\afile.exe' because it is being used by another process.

I searched around and tried just about everything. Nothing works for me. It can be fine for some time but after a while it starts to show again and i can´t compile.

I run on a Windows 7 OS. I have Avast installed and Comodo Firewall. The project is under SourceTree sourcecontroll. I have excluded the obj and bin path in programs.

I have tried changing AssemblyVersion and AssemblyFileVersion. I have tried uninstalling Avast. I have tried "ProcessExplorer" to find what process is accessing the files (0 match).

I really don´t know what more i can do? This is getting really frustrating when you are testing the code you wrote a couple of seconds ago.

I have seen old threads about this issue. Is there nothing i can do to fix this?

Upvotes: 10

Views: 34690

Answers (5)

Gail Parsloe
Gail Parsloe

Reputation: 556

What worked for me

  1. Saved the contents of the file that I couldn't save in a different file
  2. Deleted the file that I couldn't save
  3. Renamed the new file to have the old file name

Upvotes: 0

Mike
Mike

Reputation: 3311

Not one to jump on an old thread like this, but if you are setup using IIS on your local machine, IIS will sometimes keep that folder locked. An IIS Reset from the command line will take care of that, but it usually gives it up after a few minutes.

Upvotes: 0

Damon W
Damon W

Reputation: 25

While this might be an old thread, I want to second the fact that you should double check on the .exe file being closed. I ran into this issue and tried the other methods before realizing an .exe version was still open in the processes in the background. Double check for a ghost copy still running behind the scenes.

Upvotes: 1

Juw
Juw

Reputation: 2089

For anyoneelse who have this problem.

Check that your files in Debug and Bin (exe file) is not locked. That is because of another problem. Antivirus software tends to lock files. If they are locked, find out what process is using them.

If they are however not locked (like in my case). This article helped me: https://www.codeproject.com/Questions/296249/Visual-Studio-Access-Denied-Errors

"Solution 9":

Turn on windows service :- Application experience

Computer (right-click) -> manage -> Service & Application -> service -> Enable Application experience

So far that has worked for me. Never had the error since i started "Application experience.

Check also that it starts automatically.

Upvotes: 2

Pablo T. de Vargas
Pablo T. de Vargas

Reputation: 144

When I had this problem, I solved killing the process VBCSCompiler.exe and everything came back normal.

But after the latest updates of the Visual Studio I do not have more this issue.

To finalize the process, you need execute the command taskkill /F /IM VBCSCompiler.exe in cmd, or search the process in manager process of the Windows.

Upvotes: 2

Related Questions