C# – SGEN: An attempt was made to load an assembly with an incorrect format

cmsbuildnettfs

I have a project that can build fine on my local machine, however, when I get TFS to build it, I receive the following error –

SGEN: An attempt was made to load an assembly with an incorrect format:

After reading through many other posts here on this topic, most people just say I need to change the build type to either x86 or Any CPU, rather than x64, but after trying countless combinations, this was not the solution. My program is also a windows service, so setting the App Pool to allow 32 bit applications (as suggested by others) is also not the solution.

Best Answer

I encountered this same issue today. A project would not build on my PC but built fine on other PC's

I eventually fixed it by doing the following:

Right-clicked the project with the error, went into Properties

Selected the Build tab and went to the last option which is "Generate serialization assembly" I set this to Off and the project now builds fine.