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

  • Question

  • Hello.

    My solution suddenly started to not compile properly. Its attempting to copy the Exe file from the Obj directory to the Bin/Debug directory but fails.

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

    I have tried the following solutions, but without any luck:

    1. Checked that the App.Client.exe is not in the process explorer, due to the program not shutting down correctly.
    2. Tried to add the following to my Startup project prebuild event:

      if exist "$(TargetPath)"*".locked" del "$(TargetPath)"*".locked"
      if exist "$(TargetPath)" move "$(TargetPath)" "$(TargetPath)."%date:~4,2%%date:~7,2%%date:~10,4%_@_%time:~0,2%h%time:~3,2%m%time:~6,2%s%.locked

    3. Enabled diagnostic logging (Tools->Options->Projects and Solutions->Build and Run->MSBuild project build output verbosity->Diagnostic. I will will paste some of the log concentrating on the issue in this question.

    Log output (Diagnostics)

    Output files: bin\Debug\App.Client.exe.config

    Done building target "_CopyAppConfigFile" in project "App.Client.csproj".: (TargetId:925)

    Target "_CopyManifestFiles" skipped, due to false condition; ( '$(_DeploymentCopyApplicationManifest)'=='true' or '$(GenerateClickOnceManifests)'=='true' ) was evaluated as ( ''=='true' or ''=='true' ).

    Target "_CheckForCompileOutputs: (TargetId:926)" in file "C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets" from project "D:\Data\Code 2010\App.Client\App.Client.csproj" (target "CopyFilesToOutputDirectory" depends on it):

    Done building target "_CheckForCompileOutputs" in project "App.Client.csproj".: (TargetId:926)

    Target "_SGenCheckForOutputs" skipped, due to false condition; ('$(_SGenGenerateSerializationAssembliesConfig)' == 'On' or ('@(WebReferenceUrl)'!='' and '$(_SGenGenerateSerializationAssembliesConfig)' == 'Auto')) was evaluated as ('Off' == 'On' or (''!='' and 'Off' == 'Auto')).

    Target "CopyFilesToOutputDirectory: (TargetId:927)" in file "C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets" from project "D:\Data\Code 2010\App.Client\App.Client.csproj" (target "PrepareForRun" depends on it):

    Task "Copy" (TaskId:584)

    Copying file from "obj\Debug\App.Client.exe" to "bin\Debug\App.Client.exe". (TaskId:584)

    C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(2868,9): error MSB3021: Unable to copy file "obj\Debug\App.Client.exe" to "bin\Debug\App.Client.exe". The process cannot access the file 'bin\Debug\App.Client.exe' because it is being used by another process.

    Done executing task "Copy" -- FAILED. (TaskId:584)

    Done building target "CopyFilesToOutputDirectory" in project "App.Client.csproj" -- FAILED.: (TargetId:927)

    Friday, May 28, 2010 9:39 AM

Answers

  • Hi,

    Yes, i tried to disable the Visual studio hosting process, in the startup project project under debug.

    But i finally found the solution. I examined the References used by my startup project, and the project had a Reference to itself!! Therefore VS2010 was trying to copy the exe generated by the project, to the Debug folder while is was building the project, and thereby failing.

    I removed the reference, and all works fine again.

    Im somehow suprised though, how the reference got there in the first place, and why VS2010 couldnt determine that there was a circular reference?

     

     

    Monday, May 31, 2010 12:04 PM

All replies

  • Hi Anders,

    Have you tried restarting your computer?


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Ferry Meidianto | My Blog
    Friday, May 28, 2010 7:59 PM
  • hi,

    you can use unlooker tool to check which service is locking,  i', always use this to check which service is catching any folder in my build machine.

     

    Thanks

    Saturday, May 29, 2010 9:51 PM
  • Hi,

    I have tried restarting my computer, and reopened the solution. Then clean the solution and rebuild it. It didnt help im afraid, i still get the same error. If i disable the vs32host process, i dont get the error, but its unacceptable, cause the solution gets slow to work with when debugging.

     

     

    Monday, May 31, 2010 7:45 AM
  • Hi Anders,

    Do you mean you uncheck Enable the Visual Studio hosting process  checkbox in Properties > Debug, and the error message disappeared? Have you tried to delete all the files under Bin>Debug folder in this project and try again to see if it still exists?

    Regards,

    Nancy Shao [MSFT]
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg @ microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Proposed as answer by eddieaks Tuesday, August 16, 2011 1:32 PM
    Monday, May 31, 2010 9:56 AM
  • Hi,

    Yes, i tried to disable the Visual studio hosting process, in the startup project project under debug.

    But i finally found the solution. I examined the References used by my startup project, and the project had a Reference to itself!! Therefore VS2010 was trying to copy the exe generated by the project, to the Debug folder while is was building the project, and thereby failing.

    I removed the reference, and all works fine again.

    Im somehow suprised though, how the reference got there in the first place, and why VS2010 couldnt determine that there was a circular reference?

     

     

    Monday, May 31, 2010 12:04 PM
  • I have no solution for this till date. Every time, I change any line of code in codebehind and try to compile I get this very error. What I do is delete "obj" folder and it works, but I have to do this delete steps everytime I want to compile mey code. Don't know the solution yet.
    Wednesday, August 18, 2010 8:13 PM
  • I too get this same issue. My issue started when i publish this application or when i build an MSI. The only way to overcome this is to close the solution and open.
    Tuesday, August 24, 2010 1:14 PM
  • I was encountering the same issue.  I solved it by closing the solution, deleting my ProjectName.suo file, and then opening the solution again.

     

    The .suo file is supposed to be your user options file , so I think it's safe to delete. I don't know for a fact what is lost by deleting that file, however.

    • Proposed as answer by Habakkuk4 Tuesday, April 26, 2011 9:42 PM
    Monday, September 13, 2010 8:44 PM
  • I had the same problem. Changed the compilation from DEBUG to RELEASE and was able to run and debug. very strange but worked.
    Thursday, March 3, 2011 9:47 PM
  • I was encountering the same issue.  I solved it by closing the solution, deleting my ProjectName.suo file, and then opening the solution again.

     

    The .suo file is supposed to be your user options file , so I think it's safe to delete. I don't know for a fact what is lost by deleting that file, however.


    This worked for me.  I've deleted my .suo file in the past in response to other issues.  I did notice that after deleting it, VS2010 forgot which files I had open in my previous session.  Small price to pay for getting rid of this heinous issue.
    • Proposed as answer by nancy2 Friday, May 13, 2011 7:14 PM
    • Unproposed as answer by nancy2 Friday, May 13, 2011 7:14 PM
    Tuesday, April 26, 2011 9:41 PM
  • IF your Source Control Has a bin folder for your project, delete the bin folder from Source Control and then rebuild it. This would solve the problem. Having bin folder in the source control can lock the files and hence the Visual studio will not be able to copy the files.

     

    --Anonymous

    Friday, May 13, 2011 7:17 PM
  • Hi Anders,

    Do you mean you uncheck Enable the Visual Studio hosting process  checkbox in Properties > Debug, and the error message disappeared? Have you tried to delete all the files under Bin>Debug folder in this project and try again to see if it still exists?

    Regards,

    Nancy Shao [MSFT]
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg @ microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.

    it worked for me once i delete all the dll/pdb in the bin and rebuild again, but after sometime it came back again.

    i found the workaround in following thread, just to share here.

    http://connect.microsoft.com/VisualStudio/feedback/details/114694/msb3021-unable-to-copy-file-bug-still-not-fixed-in-final-version

     

    thanks.


    Tuesday, August 16, 2011 1:34 PM
  • Try :   Project >Applications Properties>Applications Tbs [ set make asingle application instance [v]]
    Tuesday, November 8, 2011 6:33 AM
  • It helped me, thanks for posting this solution.
    Friday, June 22, 2012 10:53 AM
  • Thank you so much for this idea. I was not able to get rid of this problem for month! I have tried virtually all suggestions around including renaming old copies to .locked during the build, enabling and disabling hosting process, even disconnecting solution from a team server! Nothing really helped. It is a luck that I would your reply and tried it. As soon as I deleted this crazy .suo, everything repaired and the problem never appears since then! Great, great discovery! Thanks a lot!
    • Proposed as answer by IgNiTex3 Friday, April 26, 2013 12:35 AM
    • Unproposed as answer by IgNiTex3 Friday, April 26, 2013 12:36 AM
    Saturday, March 30, 2013 5:16 PM