.NET project not building after changing the platform to x64 and back to Any CPU
Asked Answered
S

4

5

I have 5 projects in my .net c# solution. I have changed each of the projects platform to x64 in Build's platform target (This was initially 'Any CPU') and the project worked fine.

Then I changed the platform in solution properties using configuration manager in solution properties (Right Click on Solution -> Properties)

Then I changed then back to Any CPU. But I can not build the solution. There are many errors saying that dlls of each project can not be found.

One thing I noticed when I changed the platform in solution properties and built the built has changed from bin/debug to bin/x64/debug (I am running in debug mode)

Ex error :

Metadata file '[project path]\bin\Debug\Thahavuru.DataAccessLayer.dll' could not be found   

I am confused of what has to build the project successfully back again. Help is greatly appreciated.

Suspicion answered 28/11, 2013 at 11:9 Comment(4)
Check if all the project references are still intact for all the projects.Nappe
I deleted the references from the the projects and re referenced them again from the solution projects, But I was unsuccessful :(Suspicion
@ Diode, try to build the project bottom up : project with no dependency on other projects first and see what is the failure for that, if the build fails. Try again resetting the platform to x64 and see if the build succeeds for that and see what have changed.Logistics
I tried that too just now. according to the dependencies. What is happening there is when I build the project still the bin/debug is empty. That means the project is not building.Suspicion
W
9

Tinkering with the solution's Platform selection is always wrong. It is a setting that only matters to C++ projects. Managed projects get compiled to assemblies that contain MSIL, they run on any platform. It is the jitter's job to take care of this, that happens at runtime and not at build time.

It does matter for C++ projects because they get compiled to the target architecture at build time. A 64-bit DLL or EXE generated from C++ code is very different from a 32-bit one, it contains very different machine code.

A pure managed solution should therefore have only one Platform selection. Which is "AnyCPU" in old VS versions. And again in new VS versions. Microsoft fumbled it badly at VS2010 when they started creating projects that have "x86" as the default Platform selection. Creating all sorts of misery with solutions that have a drastic mix of platforms when they got upgraded from an old version of VS.

Sounds like you've dug yourself an even deeper hole where the assemblies are getting built to bin\x64\debug but the reference assemblies are still pointing to bin\debug. No real idea how you did this, you must always use project references in a solution with multiple projects that depend on each other.

I recommend serious slash-and-burn to get this problem resolved:

  • Use Build + Configuration Manager to delete extraneous platform selections until you have only one left.
  • Delete reference assemblies in a project's Reference node and re-add them with Project + Add Reference, now using the Project tab.
  • Right-click each project, Properties, Build tab. Every class library project must have its Platform Target setting at AnyCPU. Only the setting on the EXE project matters, that's the one that determines the bitness of the program. Favor AnyCPU there, if you have any dependency on native DLLs then choose between x86 and x64 to match their architecture.
  • Switch to the Release build and repeat the previous step.
Womanish answered 28/11, 2013 at 12:32 Comment(4)
Wow, this is quite informative. Thanks for the heads up. I will not play with platforms after I got to know this. Thanks. This solved the issue I am having. Thanks Hans you saved the day!!Suspicion
great guidance @Hans Passant, Do you have any documentation to provide why we shouldn't never choose the x64 platform target? I have a similar case where I need to run the application on 64-bit platform. And I don't know what really needs to be done in the application to accomplish it. The solution is .net full framework, with c++project to interact with some win32 API. And the .net project used DllImport to call the functions.Dominus
AnyCPU automatically becomes x64 on a 64-bit operating system. But since you have [DllImport] dependencies, you should pick x86 or x64 to match their build flavor.Womanish
So, if I want my .net full framework project to run as 64-bit process, I need to recompile my c++ dll to x64? Then the .net AnyCPU configuration would automatically run as x64 on a 64-bit OS?Dominus
F
1

maybe you can try to build each project separatly first. if the dll is not found it simply mean that the DataAccessLayer project is not building with success. then if it failed alone you can try to edit the cs.proj maybe you have remaining option in it. Or maybe try to add a post build instruction to each of your project which say after building with success copy myself in debug directory.

hope it helps

Fairhaired answered 28/11, 2013 at 11:15 Comment(3)
I tried that, even individual projects are not building. I am quite sure that they where working earlier but not working due to this configurationSuspicion
well try to edit your cs.proj in notepad++ if you find any remainding trace of x64. after all that if you're still blocked the ultimate solution is to create a new solution with the right config an paste all your code in it. Can you edit your .sln, and your DataAccessLayer.csproj in notepad++ and post the content?Fairhaired
Ok then I will try the hard way thenSuspicion
C
0

A related problem can cause a project to not be built by viewing the wrong platform display on the solution properties UI as compared to the platform setting of a given project.

I inherited a solution that displayed the property settings shown in the following image. Note that the solution's "Platform" is set to "Active(Mixed Platforms)" and that each project has a Platform of "Any CPU". From this, it looks like all projects should build, right? Wrong.

enter image description here

When the solution's "Platform" display is changed to "Any CPU", then it can be seen that not all of the projects have been checked under the "Build" column. Checking the appropriate "Build" checkbox here enabled my build definition to build the desired projects.

enter image description here

Colettacolette answered 7/11, 2016 at 18:5 Comment(0)
B
0

In Solution Explorer right click on Project and select Properties. Select the Build tab from the left and set platform to "All Platform" and below Platform target to "Any CPU" once build and run the project.

Properties of Project

If it works fine change the upper Platform to x64 and again build and run the project.

after changing platform to x64

It will work fine and now your build exe is built in 64-bit platform

Bettyannbettye answered 20/12, 2023 at 13:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.