简体   繁体   中英

Could not copy "obj\Debug\Program.exe" to "bin\Debug\Program.exe". Exceeded retry count of 10. Failed

I'm trying to download a file from the inte.net. I have an if statement and the else clause triggers the file download. This is my code:

if (!FileDownload)
{

}
else
{
    using (WebClient wc = new WebClient())
    {
        wc.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
        wc.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);
        wc.DownloadFileAsync(new Uri("https://www.google.com/Program.exe"),Application.StartupPath);
        MessageBox.Show("Yes");
    }

When I try to run my program I get the following errors:

Error 1:

Could not copy "obj\Debug\Program.exe" to "bin\Debug\Program.exe". Exceeded retry count of 10. Failed.

Error 2:

Unable to copy file "obj\Debug\Program.exe" to "bin\Debug\Program.exe". Could not find file 'obj\Debug\Program.exe'.

And around 10 warnings with the same message:

   Could not copy "obj\Debug\Program.exe" to "bin\Debug\Program.exe". Beginning retry 1 in 1000ms. Could not find file 'obj\Debug\Program.exe'. 

However, once I remove the else clause in my if statement, the program executes without any errors. The download code in the else clause is obviously causing the problem but I'm not sure why. I have used the same code in the same form at a different event and it's working flawlessly. Any help is appreciated.

I have already tried:

  • Close and reopen visual studio
  • Delete all the files from the bin folder then rebuild.
  • Checked if the file is locked with Process Explorer
  • Manually run VS as admin
  • Delete bin and debug folder
  • Reboot computer and move project to a different folder

Just do one thing Open Visual Studio as Administrator Rights as show in below image. 在此输入图像描述

and problem solve do below trick to exit all process after you close your application so you dont get another problems like this.

Just try this one I think you will get your solution

Add Application.Exit() in Main form or MDI form's Closing event like below

Private Sub frmMain_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing Application.Exit() End Sub

I'm sure you're not deleting the files from correct bin folder. Open the TaskManager look for any program named Program.exe . Verify where the process is running from Open file Location .

Kill the Program.exe and try rebuilding again. If it works then your bin output path is mapped to this location.

Just gave a close look at the error message: Unable to copy file "obj\\Debug\\Program.exe" to "bin\\Debug\\Program.exe". Could not find file 'obj\\Debug\\Program.exe'

Do you have any PostBuild step configured to copy files? if yes remove that.

Also edit your .csproj file and search for 'obj\\Debug' if there's anything that matches with it delete that and try again.

More advanced troubleshooting:

Use the process monitor and filter the process for VisualStudio and the path. see below screenshot

在此输入图像描述

Build your project again and Investigate the profiling logs why it's trying to copy the Program.exe.

在此输入图像描述

Add/Remove more filters to see why it's tyring to copy the Program.exe. Also look for any Errors in Result column.

I solved the problem myself. After trying lots of different solutions that had worked for other people but not for me I tried to look at the different processes running at the same time I'm trying to execute the program. The problem was Avast. I turned off Avast Anti Virus and it instantly solved the problem. For some reason Avast didn't even show any messages every time it deleted the program. I have an existing problem with my program - in that some AV's (2/72) detect my program as a virus. It has something to do with my code structure. Thanks for the answers everyone - it should be useful to other people who have a similar error.

I had the same error then I realized that I had run the project therefore after closing it and rebuilding again it was solved

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM