Bug 59502 - Getting error Error MSB6006: "sgen.exe" exited with code 1. (MSB6006) (SalesTALK)
Summary: Getting error Error MSB6006: "sgen.exe" exited with code 1. (MSB6006) (SalesT...
Status: RESOLVED DUPLICATE of bug 55697
Alias: None
Product: iOS
Classification: Xamarin
Component: MSBuild (show other bugs)
Version: XI 10.14 (d15-4)
Hardware: PC Mac OS
: Normal critical
Target Milestone: 15.4
Assignee: Bugzilla
URL:
: 60006 (view as bug list)
Depends on:
Blocks:
 
Reported: 2017-09-14 18:41 UTC by Manish Sinha
Modified: 2017-10-24 21:08 UTC (History)
10 users (show)

See Also:
Tags:
Is this bug a regression?: ---
Last known good build:


Attachments

Description Manish Sinha 2017-09-14 18:41:49 UTC
Customer issue (Vantage IT)

I have tested:-
Building my app with .NET 2.0 SOAP service in Debug config mode – works
Building my app with .NET 2.0 SOAP service in Release config mode – fails. sgen.exe error
 
To re-produce:-
File => New project (iOS single view app)
Add Web Reference (accept default for tempconvert services for .NET 2.0 Web service)
Ensure Debug config is active – then Build Solution (works)
Switch to Release config – then Build solution (fails)

Build output http://xqa.blob.core.windows.net/gist/test_build_log_diagnostic.txt-fb9e54b532954cc79762f824dcf0d79d.txt

Faced on Alpha Channel (which is 15.4 as of filing the bug)
Comment 1 Sebastien Pouliot 2017-09-14 19:17:22 UTC
    Mono Xml Serializer Generator Tool
    Mono version 4.0.30319.42000
    
    
    Unhandled Exception:
    System.Reflection.ReflectionTypeLoadException: Exception of type 'System.Reflection.ReflectionTypeLoadException' was thrown.
      at (wrapper managed-to-native) System.Reflection.Assembly:GetTypes (System.Reflection.Assembly,bool)
      at System.Reflection.Assembly.GetTypes () [0x00000] in <0f9cf89506fc472489b02664600526e9>:0 
      at Driver.Run (System.String[] args) [0x000f9] in <b91d082b5b4e4ecc9d057fcd0ad90c3e>:0 
      at Driver.Main (System.String[] args) [0x00005] in <b91d082b5b4e4ecc9d057fcd0ad90c3e>:0 
    [ERROR] FATAL UNHANDLED EXCEPTION: System.Reflection.ReflectionTypeLoadException: Exception of type 'System.Reflection.ReflectionTypeLoadException' was thrown.
      at (wrapper managed-to-native) System.Reflection.Assembly:GetTypes (System.Reflection.Assembly,bool)
      at System.Reflection.Assembly.GetTypes () [0x00000] in <0f9cf89506fc472489b02664600526e9>:0 
      at Driver.Run (System.String[] args) [0x000f9] in <b91d082b5b4e4ecc9d057fcd0ad90c3e>:0 
      at Driver.Main (System.String[] args) [0x00005] in <b91d082b5b4e4ecc9d057fcd0ad90c3e>:0 
    /Library/Frameworks/Mono.framework/Versions/5.4.0/lib/mono/msbuild/15.0/bin/Microsoft.Common.CurrentVersion.targets(3421,5): error MSB6006: "sgen.exe" exited with code 1.
    Output Item(s): SerializationAssembly=obj/iPhoneSimulator/Release/test1.XmlSerializers.dll
  Done executing task "SGen" -- FAILED.


@Manish that's a mono tool (not shipped) with XI. Can you try the current (15.4) XI with an earlier mono ?

Also please include instruction on how we can replicate issues. Thanks!
Comment 2 Ankit Jain 2017-09-14 19:24:56 UTC
This looks related to #55697. `sgen` tries to `GetTypes` for the main assembly which references XI assemblies. The runtime remaps `mscorlib 2.0.5.0` to `4.0.0.0`. And also fails to find `Xamarin.iOS`.

======================
Mono: The request to load the assembly mscorlib v2.0.5.0 was remapped to v4.0.0.0

Mono: The following assembly referenced from /Users/ankit/Projects/DM_XI_WebRef/DM_XI_WebRef/obj/iPhoneSimulator/Release/DM_XI_WebRef.exe could not be loaded:
     Assembly:   Xamarin.iOS    (assemblyref_index=1)
     Version:    0.0.0.0
     Public Key: 84e04ff9cfb79065
The assembly was not found in the Global Assembly Cache, a path listed in the MONO_PATH environment variable, or in the location of the executing assembly (/Users/ankit/Projects/DM_XI_WebRef/DM_XI_WebRef/obj/iPhoneSimulator/Release/).

Mono: The request to load the assembly System.Web.Services v2.0.5.0 was remapped to v4.0.0.0
=======================

This sounds the same as what Alex said in https://bugzilla.xamarin.com/show_bug.cgi?id=55697#c4 .

The default is to generate serialization assemblies using sgen, in non-Debug configuration, so it fails for Release only.
Comment 3 Sebastien Pouliot 2017-09-14 19:32:23 UTC
Thanks Ankit!

*** This bug has been marked as a duplicate of bug 55697 ***
Comment 4 Miguel de Icaza [MSFT] 2017-09-14 19:39:36 UTC
Ok this is not an issue with Mono, but with the way that the assemblies are being resolved.

The resulting binary contains a reference to Xamarin.iOS, and the invocation of the sgen script does not include a way for the tool to resolve the reference to Xamarin.iOS.dll

While the tool passes the assembly as a reference, it aborts immediately when running because the assembly is not loaded before we try to resolve the types on the main executable.

SIDE NOTE: I have not figured a way of running the serialized generator on the Debug configuration.   At least it does not show up on my logs.

I suspect the reason why it breaks in Release mode is that Release mode triggers the use of the tool "sgen" as an optimization, instead of relying on the runtime serializer.
Comment 5 Ankit Jain 2017-09-14 19:48:11 UTC
xbuild did not generate these serialization assemblies with sgen. But msbuild uses sgen for non-debug configs by default, and so we hit this in Release config.

The sgen step can be disabled with `/p:GenerateSerializationAssemblies=Off` on the command line or adding `<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>` to a property group in the .csproj .
Comment 6 Sebastien Pouliot 2017-09-14 20:00:12 UTC
@Ankit is this something that can be set, by default, for all SDK ? so that msbuild (on mono) behave just like xbuild did in that respect ?
Comment 8 Rolf Bjarne Kvinge [MSFT] 2017-10-06 07:30:06 UTC
*** Bug 60006 has been marked as a duplicate of this bug. ***
Comment 9 Michelangelo 2017-10-24 20:37:08 UTC
Any news? I tried to add
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
in my prom but when I compile in release I get same error.
Comment 10 Ankit Jain 2017-10-24 20:39:46 UTC
@Michelangelo, maybe you have that defined in a PropertyGroup for `Debug`? Move it to the PropertyGroup that doesn't have any condition.
Comment 11 Michelangelo 2017-10-24 21:08:37 UTC
@Ankit No way.
This is my proj

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'AdHoc|iPhone' ">
    <Optimize>false</Optimize>
    <OutputPath>bin\iPhone\AdHoc</OutputPath>
    <WarningLevel>4</WarningLevel>
    <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
  </PropertyGroup>

Note You need to log in before you can comment on or make changes to this bug.