2

I have a .net 4.5 project with a lot of nuget packages and I upgraded it to 4.7.2. To resolve some specific update problems with packages(like requireReinstallation="true" in packages.config) I upgraded related packages. Now I have upgraded packages and some new packages like

`<package id="System.AppContext" version="4.1.0" targetFramework="net472" />`
........(some other)
<package id="System.Xml.ReaderWriter" version="4.0.11" targetFramework="net472" />

At this moment, I can build it, but when I try to do it with Generate serialization assembly option I got an error in teamcity (and locally) like

C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\sgen.exe /assembly:C:\buildAgent\work\6b1c1da90609c252\Site\obj\TeamCity\Site.dll /proxytypes 
/reference:C:\buildAgent\work\6b1c1da90609c252\packages\AjaxMin.4.48.4489.28432\lib\net20\AjaxMin.dll

[SGen] C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\bin\Microsoft.Common.CurrentVersion.targets(3463, 5): warning MSB6002: The command-line for the "SGen" task is too long. Command-lines longer than 32000 characters are likely to fail. Try reducing the length of the command-line by breaking down the call to "SGen" into multiple calls with fewer parameters per call.

[SGen] C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\bin\Microsoft.Common.CurrentVersion.targets(3463, 5): error MSB6003: The specified task executable "sgen.exe" could not be run. The filename or extension is too long

Of course I can disable Generate serialization assembly but I don't want. I think the problem in too big amount of arguments in command line. After I upgraded the project the total amount of dependencies reached the limit.

How can I resolve this issue? breaking down the call to "SGen" into multiple calls with fewer parameters per call (how?) or something else

chromigo
  • 1,134
  • 1
  • 15
  • 25
  • Could you find the actual command line argument? does it exceed the limit? – kennyzx Jun 15 '18 at 09:16
  • @kennyzx yes, he exceed the limit (~38k symbols) – chromigo Jun 15 '18 at 09:18
  • I have found some old and unused code in my project. It was WebRereferense->... *..wsdl and some other types. I removed types and now sgen.exe do not generate ProjectName.XmlSerializers.dll at all. So I have decided not to use `Generate serialization assembly` sgen in my project at that moment. But anyway I will be glad to hear answer how to resolve problem with too long parameter string for sgen. – chromigo Jun 15 '18 at 10:37

2 Answers2

2

I don't think there is a simple solution. sgen does not support RSP files.

I would suggest to evaluate the command line (e.g. from msbuild logs) - the number of references (args) and file path lengths are likely not working well together. Try to restructure your project to fit into the limits (32K chars) by using less references or using shorter file path if possible.

Karel Zikmund
  • 209
  • 2
  • 7
0

When you build a C# project in Visual Studio and get the error Error MSB6003 The specified task executable "sgen.exe" could not be run. System.ComponentModel.Win32Exception (0x80004005): The filename or extension is too long you can fix it by going to the properties of the C# project, and on the Build tab set the Generate serialization assembly to off.

Apply this setting to both the Debug and Release configuration, otherwise it works locally (Debug), but fails on your build server (Release).

See XML Serializer Generator Tool (Sgen.exe) for more information on the tooling.

Novin.Kh
  • 129
  • 2
  • 6
  • Telling somebody to turn off a miscelanious setting, without explaining what that setting is or what it changes, is very wreckless. Additionally the OP said they explicitly wanted a solution that didnt do this. – Marie Apr 27 '23 at 21:19