Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio 2017 error Cannot open "X" for writing - access to path is denied

I'm sorry I cannot seem to fix this error:

enter image description here

Severity Code Description Project File Line Suppression State Error CS2012 Cannot open 'C:\Users\Usuario\source\repos\WindowsFormsApp1\WindowsFormsApp1\obj\Debug\WindowsFormsApp1.exe' for writing -- 'Access to the path 'C:\Users\Usuario\source\repos\WindowsFormsApp1\WindowsFormsApp1\obj\Debug\WindowsFormsApp1.exe' is denied.' WindowsFormsApp1 C:\Users\Usuario\source\repos\WindowsFormsApp1\WindowsFormsApp1\CSC 1 Active

I suppose it has something to do with the file being read only? I tried changing it and it reverts to read only, I tried closing and reopening VS, I tried running it as an administrator, I changed the assembly name and default namespace and now it won't even run the debugger

I'm new to C#, I used to do Java and never had an error like this one, sorry if it's something very simple. By the way I'm using Windows 10 with Bitdefender installed

like image 764
Darkly Avatar asked Jan 16 '18 16:01

Darkly


2 Answers

Had the same problem and fixed it with deleting obj directory.

Hope it helps :)

like image 196
amrezzd Avatar answered Oct 02 '22 09:10

amrezzd


This issue occurs because the dll file is open some where, suppose you try to delete the dll file from obj folder then also message appears that "The file is open in another program."

In my case, I close all VS instance and copy the root folder and paste it into another folder then open my solution in VS it works fine.

like image 28
Appu Avatar answered Oct 02 '22 07:10

Appu