locked
TFS 2010 - SGEN: An attempt was made to load an assembly with an incorrect format RRS feed

  • Question

  • Hello,

    I am facing a strange issue. TFS 2010 Build fails in Release mode. Error: "SGEN: An attempt was made to load an assembly with an incorrect format: C:\Builds\xyz\Oracle.DataAccess.dll."

    The thing is that the same build works in Debug mode. I mean if I set up the "Configuration to Build" to e.g. "x86|Debug" it works but with "x86|Release" does not.

    Changing platform configuration to "Any CPU" or x86 or x64 did not change anything. 

    So my environment.

    • Solution: VS 2010 Solution (migrated from VS 2008). Consists of 12 Projects that are compiled against Framework 4.0.
    • Team Foundation Server 2010.
    • Default Build Process Template
    • The problematic assembly Oracle.DataAccess.dll is for x86 platform (verified with Reflector). 
    here related log segment:
    Target "GenerateSerializationAssemblies: (TargetId:472)" in file "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.Common.targets" from project "C:\Builds\abc\myproject.csproj" (target "CoreBuild" depends on it):
    Building target "GenerateSerializationAssemblies" completely.
    Output file "obj\x86\Release\myproject.XmlSerializers.dll" does not exist.
    Using "SGen" task from assembly "Microsoft.Build.Tasks.v4.0, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
    Task "SGen" (TaskId:315)
     C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools\x64\sgen.exe /assembly:"C:\Builds\abc\obj\x86\Release\myproject.dll" /proxytypes 
    							/reference:"C:\Builds\xyz\Microsoft.Practices.EnterpriseLibrary.Common.dll" 
    							/reference:"C:\Builds\xyz\Microsoft.Practices.EnterpriseLibrary.Data.dll" 
    							/reference:"C:\Builds\xyz\Microsoft.Practices.EnterpriseLibrary.Logging.dll" 
    							/reference:"C:\Builds\xyz\Microsoft.Web.Services3.dll" 
    							/reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\mscorlib.dll" 
    							/reference:"C:\Builds\xyz\Oracle.DataAccess.dll" 
    							/reference:"C:\Builds\xyz\Sybase.AdoNet2.AseClient.dll" 
    							/reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.configuration.dll" 
    							/reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Core.dll" 
    							/reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Data.DataSetExtensions.dll" 
    							/reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Data.dll" 
    							/reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.dll" (TaskId:315)
     Microsoft (R) Xml Serialization support utility (TaskId:315)
     [Microsoft (R) .NET Framework, Version 4.0.30319.1] (TaskId:315)
     Copyright (C) Microsoft Corporation. All rights reserved. (TaskId:315)
    SGEN : error : An attempt was made to load an assembly with an incorrect format: C:\Builds\xyz\Oracle.DataAccess.dll. [C:\Builds\abc\myproject.csproj]
      - Could not load file or assembly 'file:///C:\Builds\xyz\Oracle.DataAccess.dll' or one of its dependencies. An attempt was made to load a program with an incorrect format. (TaskId:315)
      (TaskId:315)
     If you would like more help, please type "sgen /?". (TaskId:315)
     The command exited with code 1. (TaskId:315)
    Done executing task "SGen" -- FAILED. (TaskId:315)
    Done building target "GenerateSerializationAssemblies" in project "myproject.csproj" -- FAILED.: (TargetId:472)
    I also read this http://support.microsoft.com/default.aspx?scid=kb;en-US;2028833 article and did what it suggests but it did not help.

    I guess the issue is that the build is still using the 64 bit SGEN.exe (look at the log segment above)

    C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools\x64\sgen.exe

    I do not know how to force build to use the x86 version in the folder

    C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools

    But this is just a guess. 

     

    Does anyone have an idea or better solution?

     

    Thanks

    Thursday, December 23, 2010 10:23 PM

Answers

  • This Blog does not provide the answer - it provides a work around. Actually, if I understand it correctly this work around will negatively impact the performance.

    Meanwhile I found the solution.

    - in my case I am building x86 or 32bit solution. 

    1. Open the Build Process Template. Remember you can create a new one especially for your project and place it where you want it to. I would not recommend to change the default one.
    2. Click on the first Sequence, the big one, the outer one and open the Arguments List. Arguments list should be bellow the workflow, in the bar where the Varables and Improts and zoom of the workflow controls are.
    3. in the Arguments list find Argument with the name MSBuildPlatform of type ToolPlatform and change the value from "Microsoft.TeamFoundation.Build.Workflow.Activities.ToolPlatform.Auto" to "Microsoft.TeamFoundation.Build.Workflow.Activities.ToolPlatform.X86"
    4. save the Build Process Template and check it in in TFS. 
    5. Run the build.

     

    Monday, December 27, 2010 4:47 PM

All replies

  • Hi wesen,

    Try changing "Generate serialization assembly" from "Auto" to "Off". You can find it at Build tab of project properties.

     

    Friday, December 24, 2010 7:47 AM
  • Hi wesen,

    Thanks for posting the issue here!

    Please see the following thread and see if it helps:

    http://social.msdn.microsoft.com/Forums/en-US/asmxandxml/thread/d023ffab-c217-413b-93bb-5cfd3ae9ccd0

    Best Regards,


    Cathy Kong [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Cathy KongModerator Monday, December 27, 2010 1:03 PM
    • Unmarked as answer by wesen Monday, December 27, 2010 4:47 PM
    Friday, December 24, 2010 8:14 AM
    Moderator
  • Hi wesen,

    Is your issue solved? I am marking my reply as answer, if you have any concern with the reply, please feel free to unmark it.


    Cathy Kong [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, December 27, 2010 1:03 PM
    Moderator
  • This Blog does not provide the answer - it provides a work around. Actually, if I understand it correctly this work around will negatively impact the performance.

    Meanwhile I found the solution.

    - in my case I am building x86 or 32bit solution. 

    1. Open the Build Process Template. Remember you can create a new one especially for your project and place it where you want it to. I would not recommend to change the default one.
    2. Click on the first Sequence, the big one, the outer one and open the Arguments List. Arguments list should be bellow the workflow, in the bar where the Varables and Improts and zoom of the workflow controls are.
    3. in the Arguments list find Argument with the name MSBuildPlatform of type ToolPlatform and change the value from "Microsoft.TeamFoundation.Build.Workflow.Activities.ToolPlatform.Auto" to "Microsoft.TeamFoundation.Build.Workflow.Activities.ToolPlatform.X86"
    4. save the Build Process Template and check it in in TFS. 
    5. Run the build.

     

    Monday, December 27, 2010 4:47 PM
  • Hi wesen,

    I am sorry for not helping you, thanks for sharing the solution here!  It will be very beneficial for other community members having the similar questions.


    Cathy Kong [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, December 28, 2010 1:09 AM
    Moderator
  • Hi wesen,

    Try changing "Generate serialization assembly" from "Auto" to "Off". You can find it at Build tab of project properties.

     

    I was having a similar issue and this solution worked for me.
    Tuesday, May 31, 2011 7:04 PM
  • One of the other option to check is Build Defination - Process - Advanced options set MSBuildPlatform to x86 if you are compiling a solution which is 32 bit specific / you are not sure for the platform on TFS 2010.
    • Proposed as answer by Louis Phil Wednesday, February 15, 2012 4:24 PM
    Tuesday, July 12, 2011 5:27 AM
  • This worked for me, my app would compile fine until I added a service reference, then the TFS build started trying to bind the 64 bit system.data.dll.  Used this tip and it's fixed!!
    Thursday, March 5, 2015 11:03 PM