Q:

MSB6003 The specified task executable "sgen.exe" could not be run. The filename or extension is too long

Running VS 2017 15.5.3 on windows 10.
Getting this generic error "The specified task executable "sgen.exe" could not be run. The filename or extension is too long"
When building project in Release configuration and X64 platform.
But it builds fine in Debug configuration and Any CPU platform.
As suggested in https://developercommunity.visualstudio.com/content/problem/98090/vs-2017-153-error-the-specified-task-executable-sg.html
Was able to build it but after the  setting "Generate serialization assembly" to OFF.
Don't think the filename is long.
Would anyone shed light on this? 
Best Regards,
Damodar

A:

MSB6003 The specified task executable “sgen.exe” could not be run. The filename or extension is too long

As we know, The sgen.exe is used to created 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.
If you do not need the XML serialization assembly, you should set the property of GenerateSerializationAssemblies to Auto or off. And SGen by default only for proxy types generates for “Any CPU”. That is the reason why you got the error on the Release configuration and X64 platform but not on Debug configuration and Any CPU platform. You can right click on your project->Properties->Build->GenerateSerializationAssemblies, set the value to off. Then unload your project, edit project, in the project file, you can find the following line of code:
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>

However, this line of code on exists on the condition  Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ", So to resolve this issue, you can manually add this line of code to others conditions. Your project files configuration would end up looking something like this:
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
   ...
    <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
    ...
    <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
  </PropertyGroup>

See Generating an Xml Serialization assembly as part of my build for more detailed info.
Hope this helps.

A:

In Solution Explorer, right-click on the project throwing the error; then click on Properties.
In the window that opens, click on the Build tab by the left.
Locate the Generate serialization assembly option.
Set ti to OFF or AUTO.

