每当我试图复制4个文件到我的bin文件夹,停止主服务后,我得到一个文件(TexteDll)错误。错误是:

Cannot copy TexteDll: The requested operation cannot be performed on a file 
with a user-mapped section open

这可能是由于一些系统锁定。或者另一个进程正在使用这个DLL。当我在谷歌上搜索时,我发现重新启动系统可以解决这个问题。

有人能给出原因或者解决办法吗?我检查了TexteDll的属性(通用、版本、安全性等)。一切都很正常。


当前回答

发生在我把项目目标CPU从“任何CPU”改为“X64”,然后回到“任何CPU”之后。 通过删除Obj文件夹解决了这个问题(对于初学者:不要担心删除Obj文件夹,它将在下一次编译中重新创建)。

其他回答

在我的例子中,是资源管理器锁定了调试文件夹中编译的DLL…很奇怪,不是吗?

我是用一个叫解锁的工具发现的。

必须用Unlocker删除,即使它说文件没有锁,我不能删除文件夹,直到我不删除那个文件……

之后,它进行了编译。

编辑:

我发现了为什么在我的案例中会发生这种情况。我在Visual Studio的文本编辑器中打开了DLL…

我在windows 10, Visual Studio 2022, Visual Basic项目上遇到过。进程资源管理器“查找句柄/DLL”显示了4行devenv.exe锁定文件。

除了杀死devenv.exe,我还可以通过简单地删除包含锁定文件的文件夹来修复这个问题(在这种情况下,它是bin\Debug)。这很奇怪,因为我不允许删除锁定的文件,但我可以删除整个文件夹。

Sometimes when you double click on a warning about the referenced assembly version mismatch between two or more projects you forget to close the assembly view window and it stays there among other tabs... so you end up with the assembly being locked by VS itself and it took me quite a lot of time to figure that out :) Be careful with the power VS provides ;) Another dummy scenario. Sometimes simply deleting the whole obj folder or just the file warned as the locked one helps out with this crappy error.

我是一名开发人员,不喜欢像Unlocker这样的应用注入到注册表中。 我使用SysInternals进程资源管理器,该进程锁定了我的dll查找>查找句柄或dll [Ctrl-F]并杀死了进程。

在我的情况下,我必须杀死一个挂起的MSBuild.exe进程,该进程正在锁定文件(即使在我关闭Visual Studio之后,它仍然存在)。