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

前端 未结 4 1474
逝去的感伤
逝去的感伤 2021-02-07 12:30

I was able to find several similar questions asked and answered, but none of the answers or exact conditions applied to my situation.

  1. I have a .NET 3.5 project bei
相关标签:
4条回答
  • 2021-02-07 12:49

    This error also pops up on a build machine after installing MSBuild Toolset (for Visual Studio 2013). The problem is that only the 32bit version of sgen.exe is available by default.

    The problem disappears after installing the latest Windows SDK which includes the 64Bit version of sgen.exe:

    http://msdn.microsoft.com/en-us/windows/desktop/bg162891.aspx

    On one agent (machine) I needed to install the older version as well:

    http://msdn.microsoft.com/en-us/windows/desktop/hh852363.aspx

    0 讨论(0)
  • 2021-02-07 13:06

    Have you tried changing Generate serialization assembly to Off, as suggested in this msdn post? In my case, that was the ticket.

    Just go to your Project properties, and it's under Build.

    Project Properties - Build

    0 讨论(0)
  • 2021-02-07 13:09

    While turning serialization assembly off, will solve the problem, it is just workaround - in the end you'll pay for it with slower start up time. The problem is you have to call sgen.exe from x64 SDK (if you're targeting x64). If you're using msbuild, set correct path to sgen like this:

    <MSBuild Projects="$(MSBuildProjectLocation)" Targets="Build"
        Properties="....
        SGenToolPath=C:\Program Files\Microsoft SDKs\Windows\v6.1\Bin\x64;" 
    />
    
    0 讨论(0)
  • 2021-02-07 13:15

    This is an alternative to Ondrej's answer.

    We just made the modification for our Release configuration in the project file (csproj) and set the SDK path to the x64 version:

      <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
        ...
        ...
        ...
        <GenerateSerializationAssemblies>On</GenerateSerializationAssemblies>
        <SDK40ToolsPath>C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\x64</SDK40ToolsPath>
      </PropertyGroup>
    
    0 讨论(0)
提交回复
热议问题