27

I am working on some C# projects with Visual Studio 2005, and I am trying to change the platform target from x86 to Any CPU. I already went through all the dependencies that I know about and made sure that they were also built for Any CPU using the corflags tool.

When I change the platform target in Visual Studio 2005 it seems like it saves the change, but then when I build the project it still uses x86 anyway. The next time I open the project the platform target has been reset to x86.

This only happens for a couple of the projects in the solution, does this mean that there are other 32-bit dependencies somewhere?

I can manually run the C# compiler on the command line with /platform:anycpu and I don't get an error, but I'm not sure that is the right thing to do and I'd like to be able to build within Visual Studio.

What can I do to solve this problem?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
WildCrustacean
  • 5,896
  • 2
  • 31
  • 42
  • 2
    Are you sure that you changed the platform target in all configurations (i.e. both in Debug and Release configuration)? – Dirk Vollmar Jan 27 '10 at 14:50
  • 2
    I don't think VS cares about the dependencies. I've been able to build AnyCPU projects that had 32-bit dependencies -- that crash promptly (and appropriately) when the DLL's tried to load. Go with divo's suggestion. – Clinton Pierce Jan 27 '10 at 15:10
  • I did change the platform target in all configurations, and it still runs the compiler with /platform:x86 and doesn't save the change in the project. – WildCrustacean Jan 27 '10 at 15:11

1 Answers1

23

Make sure you've changed both the Configuration Platform and the Platform Target to Any CPU. If all else fails you can open up the .csproj and manually change the references. Right click on the Project, goto Unload Project. Then right click and goto Edit MyProject.csproj. The properties for the project may still include the default Platform as x86:

  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">x86</Platform>

Also consider the case where the Solution still has the x86 configuration in Configuration Manager. I've found for some complex Solutions with multiple projects that have different configurations I have to spend a lot of time in Configuration Manager getting everything straight.

user7116
  • 63,008
  • 17
  • 141
  • 172
  • I had changed both the Configuration Platform and Platform Target, and it still wouldn't save the change. I was able to edit the .csproj file and do it that way, so I think this is what I was looking for at this point. Whether or not it actually runs is another story. I still get the feeling that this might have to do with dependencies that I can't see being targeted for other platforms, but it's hard to say. – WildCrustacean Jan 27 '10 at 15:33
  • Came across this trying to resolve the same issue... I eventually discovered that even if a project is set to debug for, say, Debug/Any CPU in the solution configuration for Debug/Any CPU, the project's properties page, 'build' tab, lets you pick a target platform for 'Debug/Any CPU'. In my case, 'Debug/Any CPU' targeted x86 explicitly, and so when I compiled the project for Debug/Any CPU, the resulting DLL was explicitly compiled for x86... which caused Invalid Format errors when loaded in an x64 environment. And there was much 'wtf?' to be had. – James King Nov 30 '11 at 22:08
  • 1
    Just to clarify, I'm not talking about the Configuration Manager settings... there are two places to potentially mis-specify the configuration. The solution manager lets you set the project to 'Release/x64' for the 'Debug/Any CPU' configuration... the project properties' build tab lets you say 'Release/x64' targets the x86 platform. Confused yet? – James King Nov 30 '11 at 22:11
  • 1
    I know this is a little old, but having just fixed a similar issue.. I believe that the wtf issues @JamesB and others is having had is created when you attempt to change the platform target to X but it doesn't exist, so you create X but select "based on Y". Therefore you have a platform called X that has the properties of Y. You therefore need to amend the sln file explicitly in a text editor so you don;t get a mix like this: Release|x86.ActiveCfg = Release|Any CPU . – Fetchez la vache Jan 17 '13 at 16:47
  • Unloading the project and editing the .csproj worked just fine for me. And the changes reflected fine in visual studio. I deployed/published with no issues. Great solution. – eaglei22 Oct 29 '15 at 15:19