Bug 55697 - .NET 2.0 style web services fail to build under msbuild in Release but work with xbuild
Summary: .NET 2.0 style web services fail to build under msbuild in Release but work w...
Status: VERIFIED FIXED
Alias: None
Product: Tools
Classification: Mono
Component: msbuild (show other bugs)
Version: 4.8.0 (C9)
Hardware: PC Mac OS
: --- critical
Target Milestone: 15.4
Assignee: Alexander Köplinger [MSFT]
URL:
: 58099 59502 (view as bug list)
Depends on:
Blocks:
 
Reported: 2017-04-27 17:58 UTC by Chris Hamons
Modified: 2017-09-26 13:00 UTC (History)
11 users (show)

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


Attachments

Description Chris Hamons 2017-04-27 17:58:39 UTC
Steps to reproduce:

git clone https://github.com/TonyValenti/GIST_XamarinWebServicesNotWorking
xbuild WebServicesNotWorking.sln /p:Configuration=Release
msbuild WebServicesNotWorking.sln /p:Configuration=Release



"/Users/donblas/Programming/Local/GIST_XamarinWebServicesNotWorking/WebServicesNotWorking/WebServicesNotWorking.sln" (default target) (1) ->
"/Users/donblas/Programming/Local/GIST_XamarinWebServicesNotWorking/WebServicesNotWorking/WebServicesNotWorking.csproj" (default target) (2) ->
(GenerateSerializationAssemblies target) -> 
  SGEN : error CS1703: An assembly `System.Xml' with the same identity has already been imported. Consider removing one of the references [/Users/donblas/Programming/Local/GIST_XamarinWebServicesNotWorking/WebServicesNotWorking/WebServicesNotWorking.csproj]
  SGEN : error CS1703: An assembly `mscorlib' with the same identity has already been imported. Consider removing one of the references [/Users/donblas/Programming/Local/GIST_XamarinWebServicesNotWorking/WebServicesNotWorking/WebServicesNotWorking.csproj]
  SGEN : error CS1703: An assembly `System.Xml' with the same identity has already been imported. Consider removing one of the references [/Users/donblas/Programming/Local/GIST_XamarinWebServicesNotWorking/WebServicesNotWorking/WebServicesNotWorking.csproj]
  SGEN : error CS1703: An assembly `mscorlib' with the same identity has already been imported. Consider removing one of the references [/Users/donblas/Programming/Local/GIST_XamarinWebServicesNotWorking/WebServicesNotWorking/WebServicesNotWorking.csproj]
Comment 1 Chris Hamons 2017-04-27 17:58:54 UTC
From: https://forums.xamarin.com/discussion/comment/269692
Comment 2 Ankit Jain 2017-04-27 18:47:49 UTC
`sgen.exe` is throwing an exception:

  System.InvalidOperationException: Unable to generate a temporary class (result=1). (TaskId:28)
SGEN : error CS1703: An assembly `System.Web.Services' with the same identity has already been imported. Consider removing one of the references [/Users/ankit/tmp/GIST_XamarinWebServicesNotWorking/WebServicesNotWorking/WebServicesNotWorking.csproj]
SGEN : error CS1703: An assembly `System.Xml' with the same identity has already been imported. Consider removing one of the references [/Users/ankit/tmp/GIST_XamarinWebServicesNotWorking/WebServicesNotWorking/WebServicesNotWorking.csproj]
SGEN : error CS1703: An assembly `System' with the same identity has already been imported. Consider removing one of the references [/Users/ankit/tmp/GIST_XamarinWebServicesNotWorking/WebServicesNotWorking/WebServicesNotWorking.csproj]
SGEN : error CS1703: An assembly `mscorlib' with the same identity has already been imported. Consider removing one of the references [/Users/ankit/tmp/GIST_XamarinWebServicesNotWorking/WebServicesNotWorking/WebServicesNotWorking.csproj]
   (TaskId:28)
    at System.Xml.Serialization.Compiler.Compile (System.Reflection.Assembly parent, System.String ns, System.Xml.Serialization.XmlSerializerCompilerParameters xmlParameters, System.Security.Policy.Evidence evidence) [0x0021a] in <83e9d7a4b42d41219e36aa02cb194cba>:0  (TaskId:28)
    at System.Xml.Serialization.TempAssembly.GenerateAssembly (System.Xml.Serialization.XmlMapping[] xmlMappings, System.Type[] types, System.String defaultNamespace, System.Security.Policy.Evidence evidence, System.Xml.Serialization.XmlSerializerCompilerParameters parameters, System.Reflection.Assembly assembly, System.Collections.Hashtable assemblies) [0x004c2] in <83e9d7a4b42d41219e36aa02cb194cba>:0  (TaskId:28)                                                                                                                                                                                                                          at System.Xml.Serialization.XmlSerializer.GenerateSerializer (System.Type[] types, System.Xml.Serialization.XmlMapping[] mappings, System.CodeDom.Compiler.CompilerParameters parameters) [0x000cb] in <83e9d7a4b42d41219e36aa02cb194cba>:0  (TaskId:28)
    at Driver.Run (System.String[] args) [0x003e5] in <eeaf85d64a8c4c2eb792db70e13a9f1e>:0  (TaskId:28)
    at Driver.Main (System.String[] args) [0x00005] in <eeaf85d64a8c4c2eb792db70e13a9f1e>:0  (TaskId:28)

The command line to sgen doesn't have any duplicate references though. 

It works with xbuild, because xbuild doesn't have a `GenerateSerializationAssemblies` and so never calls sgen.
And this works for msbuild/debug-config because this generation is disabled by default for Debug configurations.

Since this wasn't even being used with xbuild, it's possible that sgen needs some fixes. Maybe Marek or Atsushi
have some idea why sgen is failing. Or they can suggest if the command line arguments need to be different.

User can opt out of this by setting `GenerateSerializationAssemblies=Off` in the project file or on the command line.
Comment 3 Marek Safar 2017-04-27 21:24:51 UTC
Alexander, could you figure out how to fix this?
Comment 4 Alexander Köplinger [MSFT] 2017-05-03 14:08:54 UTC
The referencesource XML serialization generator seems to always add mscorlib etc from the GAC and this conflicts with the passed in 2.0.5.0 mscorlib from xammac.

I'll look at a fix.
Comment 5 Chris Hamons 2017-06-27 18:00:03 UTC
It appears other people are hitting this here as well:

https://forums.xamarin.com/discussion/comment/283153

and on iOS as well.
Comment 6 Ludovic Henry 2017-07-12 16:48:20 UTC
*** Bug 58099 has been marked as a duplicate of this bug. ***
Comment 7 Ankit Jain 2017-09-14 12:14:37 UTC
@Alexander, ping.
Comment 8 Sebastien Pouliot 2017-09-14 19:32:23 UTC
*** Bug 59502 has been marked as a duplicate of this bug. ***
Comment 9 Sebastien Pouliot 2017-09-14 19:33:09 UTC
Affects XI customers (ref #59502)
Comment 10 Miguel de Icaza [MSFT] 2017-09-14 19:44:46 UTC
Quick band aid: considering that this has been there for a long time, can we make it so the Release configuration that runs the serializer does not do that?
Comment 11 Miguel de Icaza [MSFT] 2017-09-14 19:57:25 UTC
The suggestion is to modify this file:

Microsoft.Common.CurrentVersion.targets

And make it so this logic uses the non-generated serializers path, which is what Mono's XBuild did.

So it is a regression introduced by the switch from xbuild to msbuild, as xbuild did not support sgen at all.  So the use of sgen should be considered a new feature:

    <_SGenGenerateSerializationAssembliesConfig Condition="'$(ConfigurationName)'=='Debug' and '$(_SGenGenerateSerializationAssembliesConfig)' == 'Auto'">Off</_SGenGenerateSerializationAssembliesConfig>

Should be replaced with something like this (I am no msbuild expert, so this is an educated guess at best):

    <_SGenGenerateSerializationAssembliesConfig>Off</_SGenGenerateSerializationAssembliesConfig>

Alternatively, we could just set it to probe for Mono and disable it in that scenario.
Comment 12 Ankit Jain 2017-09-14 20:06:44 UTC
Disable sgen: https://github.com/mono/msbuild/pull/26
Comment 13 Ankit Jain 2017-09-14 20:28:54 UTC
bump to get it into mono: https://github.com/mono/mono/pull/5585
Comment 15 Luis Aguilera 2017-09-19 19:25:18 UTC
fixed in 15.4 system mono: https://github.com/mono/mono/pull/5585

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