错误:无法访问文件 bin/Debug/... 因为它正被另一个进程使用 [英] Error: Cannot access file bin/Debug/... because it is being used by another process

查看:34
本文介绍了错误:无法访问文件 bin/Debug/... 因为它正被另一个进程使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我调试我的项目时,出现以下错误:

When I debug my project, I get following error:

无法将文件objDebugMy Dream.exe"复制到binDebugMy Dream.exe".进程无法访问文件binDebugMy Dream.exe",因为它正在被另一个进程使用."

"Unable to copy file "objDebugMy Dream.exe" to "binDebugMy Dream.exe". The process cannot access the file 'binDebugMy Dream.exe' because it is being used by another process."

使用进程资源管理器,我看到 MyApplication.exe 已退出,但系统进程仍在使用它,尽管我之前停止了调试.每当我更改代码并开始调试时,它就会发生.如果我将项目复制到 USB 并调试,它运行正常.

Using Process Explorer, I see that MyApplication.exe was out but System process still uses it although I stopped debug before. Whenever I change my code and start debug it is going to happen. If I copy project to USB and debug, it runs OK.

为什么?如何修复此错误?

Why? How can I fix this error?

我使用 Window 7 Professional.使用 Xp 我从来没有遇到过这个错误.

I use Window 7 Professional. With Xp I have never got this error.

推荐答案

呃,这是一个老问题,在 Visual Studio 中仍然会偶尔出现.它咬了我几次,我已经失去了重新启动和与 VS 战斗的时间.我确定这里已经不止一次讨论过这个问题.在 MSDN 论坛上也有人讨论过它.没有实际的解决方案,但有几种解决方法.从这里开始研究.

Ugh, this is an old problem, something that still pops up in Visual Studio once in a while. It's bitten me a couple of times and I've lost hours restarting and fighting with VS. I'm sure it's been discussed here on SO more than once. It's also been talked about on the MSDN forums. There isn't an actual solution, but there are a couple of workarounds. Start researching here.

发生的事情是 VS 正在获取对文件的锁定,然后没有释放它.具有讽刺意味的是,该锁会阻止 VS 本身删除文件,以便在您重建应用程序时可以重新创建它.唯一明显的解决方案是关闭并重新启动 VS,以便它释放对文件的锁定.

What's happening is that VS is acquiring a lock on a file and then not releasing it. Ironically, that lock prevents VS itself from deleting the file so that it can recreate it when you rebuild the application. The only apparent solution is to close and restart VS so that it will release the lock on the file.

我最初的解决方法是打开 bin/Debug 文件夹并重命名可执行文件.如果它被锁定,你就不能删除它,但你可以重命名它.因此,您可以在末尾添加一个数字或其他内容,这样您就可以继续工作,而无需关闭所有窗口并等待 VS 重新启动.有些人甚至使用预构建事件自动执行此操作,将随机字符串附加到旧输出文件名的末尾.是的,这是一个巨大的 hack,但是这个问题变得如此令人沮丧和虚弱,以至于你会做任何事情.

My original workaround was opening up the bin/Debug folder and renaming the executable. You can't delete it if it's locked, but you can rename it. So you can just add a number to the end or something, which allows you to keep working without having to close all of your windows and wait for VS to restart. Some people have even automated this using a pre-build event to append a random string to the end of the old output filename. Yes, this is a giant hack, but this problem gets so frustrating and debilitating that you'll do anything.

我后来了解到,经过更多实验后,问题似乎只有在您构建项目时其中一位设计师打开时才会出现.因此,长期对我有用并阻止我再次处理这些愚蠢错误之一的解决方案是确保我始终在构建 WinForms 项目之前关闭所有设计器窗口.是的,这也有点不方便,但它确实让你不得不每小时或更多地重新启动 VS 两次.

I've later learned, after a bit more experimentation, that the problem seems to only crop up when you build the project with one of the designers open. So, the solution that has worked for me long term and prevented me from ever dealing with one of those silly errors again is making sure that I always close all designer windows before building a WinForms project. Yes, this too is somewhat inconvenient, but it sure beats the pants off having to restart VS twice an hour or more.

我认为这也适用于 WPF,虽然我不使用它,也没有亲身经历过那里的问题.

I assume this applies to WPF, too, although I don't use it and haven't personally experienced the problem there.

我还没有尝试在 VS 2012 RC 上重现它.不知道那里修好了没有.但到目前为止,我的经验是,即使在微软声称已修复它之后,它仍然设法弹出.它仍然存在于 VS 2010 SP1 中.当然,我并不是说他们的程序员是不知道自己在做什么的白痴.我认为导致该错误的原因有多种和/或很难在实验室中可靠地重现.这与我没有亲自提交任何错误报告的原因相同(尽管我已经为其他人 +1),因为我似乎无法可靠地重现它,就像可恶的雪人一样.

I also haven't yet tried reproducing it on VS 2012 RC. I don't know if it's been fixed there yet or not. But my experience so far has been that it still manages to pop up even after Microsoft has claimed to have fixed it. It's still there in VS 2010 SP1. I'm not saying their programmers are idiots who don't know what they're doing, of course. I figure there are just multiple causes for the bug and/or that it's very difficult to reproduce reliably in a laboratory. That's the same reason I haven't personally filed any bug reports on it (although I've +1'ed other peoples), because I can't seem to reliably reproduce it, rather like the Abominable Snowman.

<结束针对任何人的咆哮>

这篇关于错误:无法访问文件 bin/Debug/... 因为它正被另一个进程使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆