Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 779
diyoda_ Avatar asked Dec 26 '22 17:12

diyoda_


2 Answers

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. Choose between x86 and AnyCPU. Never use x64.
  • Switch to the Release build and repeat the previous step.
like image 189
Hans Passant Avatar answered Dec 28 '22 06:12

Hans Passant


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

like image 38
Franck Ngako Avatar answered Dec 28 '22 05:12

Franck Ngako