wpf 错误 CS2012:无法打开 <可执行路径> 访问 <可执行路径被拒绝>

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37552769/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 13:49:46  来源:igfitidea点击:

error CS2012: Cannot open <executable path> access to <executable path denied>

c#wpfbuild

提问by Grigoris Dimitroulakos

I was working on a WPF application in Visual Studio 2015 and all went well until unexpectedly the build dropped me the CS2012 error inform me that it cannot access/update the executable in the /Debug directory.

我正在 Visual Studio 2015 中处理 WPF 应用程序,一切顺利,直到构建出人意料地丢弃了我,CS2012 错误通知我它无法访问/更新 /Debug 目录中的可执行文件。

I tried the following and it didn't work:

我尝试了以下方法,但没有奏效:

  1. Restart
  2. Close VS and open the application again
  3. Build->Clean
  1. 重新开始
  2. 关闭VS并再次打开应用程序
  3. 构建->清洁

I couldn't find any solution in the web so I tried: 1. to move the whole project directory to another location. 2. creating a new WPF project and assembling it file by file with copy/pastes.

我在网上找不到任何解决方案,所以我尝试: 1. 将整个项目目录移动到另一个位置。2.创建一个新的WPF项目并通过复制/粘贴逐个文件地组装它。

The weird thing was that in both cases the application worked in the new location. I continued the experimentation (in the original directory) and i tried to build a "Hello World" Console application in the same directory. The result was that the trivial console application didn't work and produced the same problem as the WPF application (CS2012 error).

奇怪的是,在这两种情况下,应用程序都在新位置运行。我继续实验(在原始目录中)并尝试在同一目录中构建“Hello World”控制台应用程序。结果是普通的控制台应用程序不起作用并产生与 WPF 应用程序相同的问题(CS2012 错误)。

Since I haven't noticed any activity of another program (i.e., antivirus) trying to quarantine (or changing the file/folder permissions of) this folder, I assume that this has been done by VS somehow but I don't know why. Perhaps it is a bug.

由于我没有注意到其他程序(即防病毒软件)尝试隔离(或更改其文件/文件夹权限)的任何活动,因此我认为这是由 VS 以某种方式完成的,但我不知道为什么。也许这是一个错误。

Is anyone has a logical explanation about this problem? And a way to fix it?

有没有人对这个问题有一个合乎逻辑的解释?以及修复它的方法?

采纳答案by jabu.hlong

I found that my other running solution was referencing the same < executable path>.

我发现我的另一个正在运行的解决方案引用了相同的 <executable path>。

Just make sure that no other process is using the referenced folder/file/dll

只要确保没有其他进程正在使用引用的文件夹/文件/dll

回答by M.Dogus

Sometimes antivirus softwares can block copying an exe file from a folder to any path. You can manage by settings or the easiest way is to shut down live protection while you are coding and debugging. :)

有时防病毒软件可以阻止将 exe 文件从文件夹复制到任何路径。您可以通过设置进行管理,或者最简单的方法是在编码和调试时关闭实时保护。:)

回答by Todd Shearer

I have experience the same thing today. My company forced a system update that installs microsoft updates.

我今天也经历了同样的事情。我的公司强制进行系统更新以安装微软更新。

Now, I create a new Winform project, with just a blank form...get the same error.

现在,我创建了一个新的 Winform 项目,只有一个空白表单......得到同样的错误。

If I open an existing solution, I don't get the error, it's just for new solutions/projects.

如果我打开一个现有的解决方案,我不会收到错误,它只是针对新的解决方案/项目。