Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS 2010, TFS 2013 SGEN: An attempt was made to load an assembly with an incorrect format

I am working on a conversion of tfs 2013 build definition, we were initially using tfs 2008.I have a new server with TFS2013 installed and working on Build definition for 2013 xaml (workflow) customization is completed. However i am facing an error when my TFS build in release mode for Any Cpu configuration, but its fine when i use debug mode. I have tried looking many articles and unable to find any solution kindly help me here. This is fine in my local machine but happens only in the server.

Project and details

1) project is .net framework 4.0

2)Default configuration is "Any Cpu"

3)TFS 2013 server is 64 bit, windows server 2008 r2

Build Definition

Configuration : Any CPU|Release

MsBuildPlatform : x86

Error: SGEN: An attempt was made to load an assembly with an incorrect format: C:\Windows\Microsoft.Net\assembly\GAC_64\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll.

Warning: C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets (990): The reference assemblies for framework ".NETFramework,Version=v4.0" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend.

I have installed windos 8 SDK (Tools only) and Windows framework 4 x64 as x86 version is failing

The folder C:\Program Files\Microsoft SDKs\Windows has v7.0 folder C:\Program Files (x86)\Microsoft SDKs\Windows has v8.1A folder

where as my local machine has many versions inside the windows folder in above path

List of related articles which i have checked,but couldn't find a solution

http://seravy.wordpress.com/2012/10/25/installing-net-4-5-and-not-windows-sdk-8/

http://blogs.msdn.com/b/windowssdk/archive/2009/09/16/windows-7-sdk-setup-common-installation-issues-and-fixes.aspx

Running MSBuild fails to read SDKToolsPath

http://dukelupus.wordpress.com/2008/02/05/task-failed-because-sgenexe-was-not-found-solution/

How do I fix the Visual Studio compile error, "mismatch between processor architecture"?

TFS 2010 creating .Net 4.0 XmlSerializers DLL for .Net 3.5 Application

So what should i do to fix this error ?

like image 594
Dilip Avatar asked Jun 04 '14 14:06

Dilip


3 Answers

You need to install the targeting packs (aka SDK, aka Developer pack) for the .NET Framework version you are targeting. You can download them all from http://blogs.msdn.com/b/dotnet/p/dotnet_sdks.aspx

Specifically for your question and targeting .NET Framework 4.0, you want Windows SDK for Windows 7 and .NET Framework 4 Sounds like you grabbed the Windows 8 SDK, which is not what you want for targeting .NET Framework 4.0.

like image 100
Dude0001 Avatar answered Nov 11 '22 01:11

Dude0001


This is not a very good answer (but in case someone comes across it like me), and does not provide insight into why it is occurring. But turning off "Generate the serialization assembly" on the offending project does allow for the build to work in my case.

Start up times will be slower, as serialization will occur at runtime instead now.

like image 40
BenM Avatar answered Nov 11 '22 01:11

BenM


You simply need to see what framework you are using and then what debug mode you are using. In my case i was using framework 4.0 and Build mode target framework "any cpu" but after searching around i found that i need to upgrade my .Net framework from 4.0 to 4.5 and i have to build my solution from "any cpu" to x86 framework because i had Windows 7 SPI with x86 architecture.

Here are some images what i have done to solve this error. enter image description hereenter image description here

like image 1
Ammar Asjad Avatar answered Nov 11 '22 02:11

Ammar Asjad