[英]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.我正在尝试从 inte.net 下载文件。 I have an if statement and the else clause triggers the file download.我有一个 if 语句,else 子句触发文件下载。 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:以及大约 10 个带有相同消息的警告:
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.但是,一旦我删除了 if 语句中的 else 子句,程序就会执行而不会出现任何错误。 The download code in the else clause is obviously causing the problem but I'm not sure why. else 子句中的下载代码显然是导致问题的原因,但我不确定为什么。 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:我已经尝试过:
Just do one thing Open Visual Studio as Administrator Rights as show in below image. 只需做一件事打开Visual Studio作为管理员权限,如下图所示。
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 在Main窗体或MDI窗体的Closing事件中添加Application.Exit() ,如下所示
Private Sub frmMain_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing Application.Exit() End Sub Private Sub frmMain_FormClosing(sender As Object,e As System.Windows.Forms.FormClosingEventArgs)处理Me.FormClosing Application.Exit()End Sub
I'm sure you're not deleting the files from correct bin
folder.我确定你没有从正确的 bin
文件夹中删除文件。Open the TaskManager
look for any program named Program.exe
.打开 TaskManager
查找名为Program.exe
任何程序。Verify where the process is running from Open file Location
.从 Open file Location
验证进程的运行Open file Location
。
Kill the Program.exe
and try rebuilding again.杀死 Program.exe
并再次尝试重建。If it works then your bin output path is mapped to this location. 如果它工作,那么bin输出路径将映射到此位置。
Just gave a close look at the error message: Unable to copy file "obj\\Debug\\Program.exe" to "bin\\Debug\\Program.exe". 只是仔细看看错误消息:无法将文件“obj \\ Debug \\ Program.exe”复制到“bin \\ Debug \\ Program.exe”。 Could not find file 'obj\\Debug\\Program.exe' 找不到文件'obj \\ Debug \\ Program.exe'
Do you have any PostBuild step configured to copy files? 您是否配置了任何PostBuild步骤来复制文件? 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. 还要编辑你的.csproj文件并搜索'obj \\ Debug'如果有任何匹配它的内容删除它并重试。
More advanced troubleshooting: 更高级的故障排除
Use the process monitor and filter the process for VisualStudio and the path. 使用过程监视器并过滤VisualStudio和路径的过程。 see below screenshot 见下面的截图
Build your project again and Investigate the profiling logs why it's trying to copy the Program.exe. 再次构建项目并调查分析日志,以便它尝试复制Program.exe。
Add/Remove more filters to see why it's tyring to copy the Program.exe. 添加/删除更多过滤器,以查看复制Program.exe的原因。 Also look for any Errors in Result
column. 还要查找“ Result
列中的任何“错误”。
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. 问题是Avast。 I turned off Avast Anti Virus and it instantly solved the problem. 我关闭了Avast Anti Virus,它立即解决了这个问题。 For some reason Avast didn't even show any messages every time it deleted the program. 出于某种原因,Avast每次删除程序时都没有显示任何消息。 I have an existing problem with my program - in that some AV's (2/72) detect my program as a virus. 我的程序存在问题 - 因为某些AV(2/72)将我的程序检测为病毒。 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我遇到了同样的错误,然后我意识到我已经运行了该项目,因此在关闭它并再次重建后它就解决了
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.