C# 在 Visual Studio 2008 中调试时“不允许更改 64 位应用程序”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1498464/
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-08-06 18:09:39  来源:igfitidea点击:

"Changes to 64-bit applications are not allowed" when debugging in Visual Studio 2008

c#visual-studio64-bitedit-and-continue

提问by ripper234

I'm using Visual Studio 2008, C#. I try to use edit-and-continue (edit the code while debugging), and get this exception:

我使用的是 Visual Studio 2008,C#。我尝试使用编辑并继续(在调试时编辑代码),并得到这个异常:

"Changes to 64-bit applications are not allowed"

“不允许更改 64 位应用程序”

Why is that? Is there a workaround?

这是为什么?有解决方法吗?

采纳答案by JaredPar

Edit and Continue is not supported on 64 bit applications at the CLR level so there is no way for Visual Studio to implement it either.

CLR 级别的 64 位应用程序不支持“编辑并继续”,因此 Visual Studio 也无法实现它。

The easiest way to work around this problem is to target your application to x86 chips. This will cause it to run in Wow64 mode as a 32 bit process and hence be able to ENC. You can do this by doing the following

解决此问题的最简单方法是将您的应用程序定位到 x86 芯片。这将导致它作为 32 位进程在 Wow64 模式下运行,因此能够进行 ENC。您可以通过执行以下操作来做到这一点

  1. Right click on the .EXE application and choose Properties
  2. Go to the Build Tab
  3. Change the Platform Target combo box to x86
  1. 右键单击 .EXE 应用程序并选择属性
  2. 转到构建选项卡
  3. 将平台目标组合框更改为 x86

enter image description here

在此处输入图片说明

回答by jcopenha

The edit-and-continue feature simply hasn't been implemented in x64 yet. I haven't heard any updates on when they plan to do it yet.

编辑并继续功能还没有在 x64 中实现。我还没有听说他们计划何时进行任何更新。

See also Why doesn't Edit and Continue work on the x64 CLR?

另请参阅为什么“编辑并继续”在 x64 CLR 上不起作用?

回答by Vadim

Like jcopenha said there's no edit-and-continue on x64 yet. Current version of the 64bit CLR does not support it. However, there's a work around.

就像 jcopenha 所说的那样,x64 上还没有编辑和继续。当前版本的 64 位 CLR 不支持它。但是,有一个解决方法。

You can find it on Bug Babble post.

你可以在Bug Babble 帖子上找到它。

You need to compile your managed assembly with a target CPU of x86. This will cause the 32 bit CLR to be used rather than the 64 bit CLR.

For a VB Project, right click on the project and go to Properties/Compile/Advanced Compile Options/Target CPU and set it to "x86". For a C# Project, right click on the project and go to Properites/Build/Platform Target and set it to "x86".

您需要使用 x86 的目标 CPU 编译托管程序集。这将导致使用 32 位 CLR 而不是 64 位 CLR。

对于 VB 项目,右键单击项目并转到属性/编译/高级编译选项/目标 CPU 并将其设置为“x86”。对于 C# 项目,右键单击该项目并转到 Properites/Build/Platform Target 并将其设置为“x86”。

Hope it helps.

希望能帮助到你。

回答by Jane

I had the same error message in MS Visual C# Express 2010. It was funny though, because the application was definitely configured as an x86 Project!

我在 MS Visual C# Express 2010 中遇到了相同的错误消息。不过这很有趣,因为该应用程序确实被配置为 x86 项目!

In the end, it was the following line missing in my .csproj file:

最后,我的 .csproj 文件中缺少以下行:

<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'MY_CONFIG|x86'">
    ...
    <PlatformTarget>x86</PlatformTarget>
    ...
</PropertyGroup>

I don't know why it was missing ... I guess MS Visual C# Express 2010 is not bugfree ;)

我不知道为什么它会丢失......我猜 MS Visual C# Express 2010 不是无错误的 ;)

回答by kenchilada

The "Edit and Continue" feature for 64-bit code will be supported under Visual Studio 2013.

Visual Studio 2013 将支持 64 位代码的“编辑并继续”功能。

More information here.

更多信息在这里

回答by Steve Pitchers

Personally, what I actually want is stop-and-edit not edit-and-continue.

就个人而言,我真正想要的是停止和编辑而不是编辑和继续。

So I simply turn off Tools / Options / Debugging / Edit and Continue.

所以我只是关闭工具/选项/调试/编辑并继续。

Doing so inhibits that pesky dialog box from pestering me about a missing feature I didn't want in the first place :-)

这样做可以阻止那个讨厌的对话框纠缠我关于我首先不想要的缺失功能:-)

回答by Joseph Wu

  1. when Target CPU is set to 'Any CPU', it will run as a 32bit application on a 32bit windows, and 64bit application on a 64bit windows. However visual studio does not allow 'edit-and-continue' feature for 64bit application.

  2. In order to debug 'fluently' on 64bit machine, we can either:

    a) set 'Target CPU' to 'Any CPU' but check the 'Prefer 32bit' box.

    b) or, set 'Target CPU' to 'x86'

  1. 当目标 CPU 设置为“任何 CPU”时,它将在 32 位窗口上作为 32 位应用程序运行,在 64 位窗口上作为 64 位应用程序运行。但是,visual studio 不允许 64 位应用程序的“编辑并继续”功能。

  2. 为了在 64 位机器上“流畅”地调试,我们可以:

    a) 将“Target CPU”设置为“Any CPU”,但选中“Prefer 32bit”框。

    b) 或者,将“目标 CPU”设置为“x86”

VERY important: both option requires the 'Enable optimizations' box to be unChecked.

非常重要:这两个选项都需要取消选中“启用优化”框。

回答by AhmAr KAka

Unfortunately, Edit and Continue isn't supported on 64-bit. In fact, if you try to use Edit & Continue when debugging a 64-bit application, you get the following error message: "Changes to 64-bit applications are not allowed" Many users may not be aware that by default, when you create a C# or VB project in Visual Studio 2008, the "Platform" for the project is set to "Any CPU". This means that if you run your application on a 32-bit operating system, your application will run as a 32-bit process and similarly, if you run your application on a 64-bit operating system, the application will be 64-bit. The consequence of "Any CPU" is that when you try to debug your application on a 64-bit operating system, you won't be able to use the Edit and Continue feature.

不幸的是,64 位不支持编辑并继续。事实上,如果您在调试 64 位应用程序时尝试使用“编辑并继续”,您会收到以下错误消息:“不允许更改 64 位应用程序”许多用户可能不知道默认情况下,当您创建Visual Studio 2008 中的 C# 或 VB 项目,项目的“平台”设置为“任何 CPU”。这意味着如果您在 32 位操作系统上运行您的应用程序,您的应用程序将作为 32 位进程运行,同样,如果您在 64 位操作系统上运行您的应用程序,则应用程序将是 64 位的。“任何 CPU”的结果是,当您尝试在 64 位操作系统上调试应用程序时,您将无法使用“编辑并继续”功能。

However, there is a workaround. During development, you can set the Platform for your project to 32-bit which means that your application will run as a 32-bit process even on a 64-bit operating system. This is known as WOW64 or "Windows On Windows" which basically means that you can run a 32-bit application on a 64-bit operating system.

但是,有一个解决方法。在开发过程中,您可以将项目的平台设置为 32 位,这意味着即使在 64 位操作系统上,您的应用程序也将作为 32 位进程运行。这被称为 WOW64 或“Windows On Windows”,这基本上意味着您可以在 64 位操作系统上运行 32 位应用程序。

So, how do you set the Platform for your project to 32-bit? Well, you need to create a 32-bit platform using the Visual Studio Configuration Manager. Here is a short walkthrough.

那么,如何将项目的平台设置为 32 位?那么,您需要使用 Visual Studio 配置管理器创建一个 32 位平台。这是一个简短的演练。

First, open the "Configuration Manager" dialog from Build –> Configuration Manager. The Configuration Manager dialog is shown below.

首先,从 Build –> Configuration Manager 打开“Configuration Manager”对话框。配置管理器对话框如下所示。