11

After moving my build server I get the following error:

C:\Windows\Microsoft.NET\Framework64\v3.5\Microsoft.Common.targets (1682): Could not run the "GenerateResource" task because MSBuild could not create or connect to a task host with runtime "CLR2" and architecture "x64". Please ensure that (1) the requested runtime and/or architecture are available on the machine, and (2) that the required executable "MSBuildTaskHost.exe" exists and can be run.

My configuration says this:

<ConfigurationToBuild Include="Release|Any CPU">
    <FlavorToBuild>Release</FlavorToBuild>
    <PlatformToBuild>Any CPU</PlatformToBuild>
 </ConfigurationToBuild>

What am I missing?

Rahul Nikate
  • 6,192
  • 5
  • 42
  • 54
dexter
  • 7,063
  • 9
  • 54
  • 71

6 Answers6

13

To resolve this, Go to your .csproj file and open with notepad.

Add the following line under the default property group:

<PropertyGroup>
      <DisableOutOfProcTaskHost>true</DisableOutOfProcTaskHost>
</PropertyGroup>

Project should compile now.

Rahul Nikate
  • 6,192
  • 5
  • 42
  • 54
  • 2
    See https://connect.microsoft.com/VisualStudio/feedback/details/758772/generateresource-fails-for-net-3-5-application-when-net-4-5-has-been-installed for a much longer discussion of it. Basically, it is a workaround for a known issue with .NET 3.5.1. Thanks Rahul Nikate for providing such an exact example. This fixed it for me! – MBentley Apr 26 '16 at 19:48
  • @MBentley Welcome and Thanks for the link. – Rahul Nikate Apr 27 '16 at 04:03
  • Alas, the link above has been disappeared. – Ryan Lundy Jan 16 '19 at 09:28
8

In my case, I received that error message when trying to build a solution on a 32-bit Windows 7 machine. The way to resolve the error for me was to right-click on the project in VS, choose properties, then go to the Build tab. In here I changed the "Platform target" from "Any CPU" to "x86". HTH

user8128167
  • 6,929
  • 6
  • 66
  • 79
  • 1
    Building a simple WinForm with VS 2013, same problem. Switched to x86 under Compile tab, Target CPU and built successfully; switched back to AnyCPU and successfully built again. –  Mar 04 '15 at 17:06
4

Another approach is to do the following

Click Start ->> right-click Computer ->> Properties ->> Advanced system settings ->> click Environment Variables button to open the dialog,

then under the System variables section, click New… button, type the Variable name = DISABLEOUTOFPROCTASKHOST, and type the Variable value = 1,

then click Ok.

This should suppress this error.

2

You need to install .NET SDK for the version of .NET that you are using. Here is a link for .NET 3.5 Where is the .net 3.5 SDK? and here is a link for 4.0 http://www.microsoft.com/en-us/download/details.aspx?id=8279

Installing Visual Studio will install the right SDK as well, but may not be a good option for you.

I hope that helps.

Community
  • 1
  • 1
Biser C.
  • 553
  • 5
  • 11
2

The core problem is the fact that an 64-bit executable can not load a 32-bit dll and vice-versa.

"Auto" means that . NET assembly will switch at runtime between the platforms, depending on what platform is on the machine it is currently running on.

So having a .NET assembly compiled with "Auto" loading an 32-bit dll is a problem waiting to happen, and this is what this error is all about.

To correct it, if you are NOT using any native dlls, go to the properties of the project for every managed project and set "target CPU" to be the same as currently selected "Platform", for all available platforms.

If you are using native dlls, you have to define 2 build configurations one for 32 bit and one for 64 bit, link (refer) the correct versions of the dlls and install according to the target computer platform.

Pifcnt
  • 117
  • 1
  • 10
  • Do not fully understand the "If you are using native dlls" part. could you please elaborate. I am facing the issue as told in the question. I feel your answer could help – Abdus Khazi Nov 22 '16 at 15:38
1

I resolved this issue by opening VS2010 as administrator.

Kamal
  • 19
  • 1