sgen.exe fails during build

后端 未结 5 511
时光取名叫无心
时光取名叫无心 2021-01-17 10:22

After changing the output directory of a visual studio project it started to fail to build with an error very much like:

C:\\Program Files\\Microsoft Visu         


        
相关标签:
5条回答
  • 2021-01-17 10:52

    I ran into this issue when I had referenced an assembly on a web site project in the GAC that had been since uninstalled, and for some reason that reference triggered a serialization assembly generation, and sgen choked on the reference (since it no longer existed). After removing the reference and turning serialization assembly generation to Off, I no longer had the issue.

    0 讨论(0)
  • 2021-01-17 10:55

    It looks reasonable enough to me, unless something is imposing a 4096 character limit [you list 4020 characters]

    A 4096 limit to me seems a bit absurd, it'd be 2048 or 32767 or 8192 from stuff I've found by searching for the command-line limits.

    0 讨论(0)
  • 2021-01-17 10:57

    see msdn for the options to sgen.exe [you have the command line, you can play with it manually... delete your .XmlSerializers.dll or use /force though]

    Today I also ran across how to more manually specify the sgen options. I wanted this to not use the /proxy switch, but it appears it can let you specify the output directory. I don't know enough about msbuild to make it awesome, but this should get you started [open your .csproj/.vbproj in your non-visual studio editor of choice, look at the bottom and you should be able to figure out how/where this goes]

    [the below code has had UseProxyTypes set to true for your convenience]

    <Target Name="GenerateSerializationAssembliesForAllTypes"
      DependsOnTargets="AssignTargetPaths;Compile;ResolveKeySource"
      Inputs="$(MSBuildAllProjects);@(IntermediateAssembly)"
      Outputs="$(OutputPath)$(_SGenDllName)">
        <SGen BuildAssemblyName="$(TargetFileName)"
          BuildAssemblyPath="$(OutputPath)" References="@(ReferencePath)"
          ShouldGenerateSerializer="true" UseProxyTypes="true"
          KeyContainer="$(KeyContainerName)" KeyFile="$(KeyOriginatorFile)"
          DelaySign="$(DelaySign)" ToolPath="$(SGenToolPath)">
            <Output TaskParameter="SerializationAssembly"
              ItemName="SerializationAssembly" />
         </SGen>
    </Target>
    <!-- <Target Name="BeforeBuild">
    </Target> -->
    <Target Name="AfterBuild"
      DependsOnTargets="GenerateSerializationAssembliesForAllTypes">
    </Target>
    
    0 讨论(0)
  • 2021-01-17 11:01

    I've not seen this particular problem, but recently for us a "C1001: An internal error has occurred in the compiler" type crash from cl.exe was fixed after installing some random and unrelated (or so we thought) Windows security updates.

    We knew the code didn't crash the compiler on other machines using the same version and service pack level of Visual Studio, but we were really clutching at straws when we tried the Windows security updates.

    0 讨论(0)
  • 2021-01-17 11:05

    If you are having this problem while building your VS.NET project in Release mode here is the solution:

    Go to the project properties and click on the Build tab and set the value of the "Generate Serialization Assembly" dropdown to "Off".

    Sgen.exe is "The XML Serializer Generator creates an XML serialization assembly for types in a specified assembly in order to improve the startup performance of a XmlSerializer when it serializes or deserializes objects of the specified types." (MSDN)

    0 讨论(0)
提交回复
热议问题