Bug 17368 - Unable to compile fsharp against latest (3.2.7) mono
Summary: Unable to compile fsharp against latest (3.2.7) mono
Alias: None
Product: Runtime
Classification: Mono
Component: General ()
Version: 3.2.x
Hardware: Other Linux
: High blocker
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2014-01-22 09:04 UTC by Karl Nilsson
Modified: 2014-01-27 18:38 UTC (History)
9 users (show)

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

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Karl Nilsson 2014-01-22 09:04:21 UTC
When attempting to build the fsharp project (https://github.com/fsharp/fsharp) with mono 3.2.7 it fails with the attached exception. Building fsharp against 3.2.5 succeeds. 


make[3]: Entering directory `/home/knocte/Documents/Code/OpenSource/fsharpFORMONOENV/src/fsharp/FSharp.Build-proto'
MONO_ENV_OPTIONS=--gc=sgen xbuild /p:Configuration=Proto
XBuild Engine Version 12.0
Mono, Version
Copyright (C) 2005-2013 Various Mono authors

Build started 1/14/2014 5:11:16 PM.
Project "/home/knocte/Documents/Code/OpenSource/fsharpFORMONOENV/src/fsharp/FSharp.Build-proto/FSharp.Build-proto.fsproj" (default target(s)):
    Target CallFsSrGen:
        Created directory "obj/proto/./"
: error : Error initializing task FsSrGen: Cannot cast from source type to destination type.
    Task "FsSrGen" execution -- FAILED
    Done building target "CallFsSrGen" in project "/home/knocte/Documents/Code/OpenSource/fsharpFORMONOENV/src/fsharp/FSharp.Build-proto/FSharp.Build-proto.fsproj".-- FAILED
Done building project "/home/knocte/Documents/Code/OpenSource/fsharpFORMONOENV/src/fsharp/FSharp.Build-proto/FSharp.Build-proto.fsproj".-- FAILED


/home/knocte/Documents/Code/OpenSource/fsharpFORMONOENV/src/fsharp/FSharp.Build-proto/FSharp.Build-proto.fsproj (default targets) ->
/home/knocte/Documents/Code/OpenSource/fsharpFORMONOENV/lib/bootstrap/2.0/FSharp.SRGen.targets (CallFsSrGen target) ->

    : error : Error initializing task FsSrGen: Cannot cast from source type to destination type.

     0 Warning(s)
     1 Error(s)

Time Elapsed 00:00:00.2587960
make[3]: *** [build-proto] Error 1
make[3]: Leaving directory `/home/knocte/Documents/Code/OpenSource/fsharpFORMONOENV/src/fsharp/FSharp.Build-proto'
make[2]: *** [build-proto] Error 2
make[2]: Leaving directory `/home/knocte/Documents/Code/OpenSource/fsharpFORMONOENV/src/fsharp'
make[1]: *** [all] Error 2
make[1]: Leaving directory `/home/knocte/Documents/Code/OpenSource/fsharpFORMONOENV/src/fsharp'
make: *** [all] Error 2
Comment 1 donsyme 2014-01-22 09:22:50 UTC
It looks like there has been some kind of change to resource naming (or something like that) in Mono 3.2.x, which is affecting the bootstrap copy of FSharp.Build.dll used by xbuild in the F# build.

Does anyone know if anything has changed in this area in the last month or so?
Comment 2 Andres G. Aragoneses 2014-01-22 09:47:42 UTC
> Does anyone know if anything has changed in this area in the last month or so?

Yes, definitely. Michael Hutchinson and Atsushi Eno have been fixing xbuild to make it compatible with MSBuild files created by the new VS2013. There have been *a lot* of commits so this is could be the culprit of the regression.
Comment 3 Juraj Skripsky 2014-01-22 11:50:08 UTC
The following commit seems to trigger the bug:

commit 5e70ba51a0cb57dd878f08f59d0f0718867d5218
Author: Michael Hutchinson <m.j.hutchinson@gmail.com>
Date:   Fri Dec 20 03:55:57 2013 -0500

    [xbuild] Make xbuild script point to xbuild 12
Comment 4 Andres G. Aragoneses 2014-01-22 11:52:05 UTC
Ok, can someone change the product from "Other" to "xbuild" please?
Comment 5 Karl Nilsson 2014-01-22 13:54:33 UTC
Sure. Changed.
Comment 6 Mikayla Hutchinson [MSFT] 2014-01-23 16:46:12 UTC
This appears to be a runtime bug. The issue is that FSharp.SRGen.Build.Tasks contains a task that subclasses Microsoft.Build.Utilities.ToolTask from the "Microsoft.Build.Utilities.v3.5, Version=v3.5.0.0" assembly, which implements Microsoft.Build.Framework.ITask from "Microsoft.Build.Framework, Version=v3.5.0.0".

xbuild.exe 12.0 loads the task and tries to cast it to a Microsoft.Build.Framework.ITask, from "Microsoft.Build.Framework, Version=v12.0.0.0". The runtime (correctly) does not consider the ITask interfaces to be compatible since they are from differently versioned assemblies, and throws an ICE.

EXCEPT! xbuild.exe.config contains a binding redirect:

	<assemblyIdentity name="Microsoft.Build.Framework" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
	<bindingRedirect oldVersion="" newVersion="" />

So the "Microsoft.Build.Framework, v3.5.0.0" reference should have been rewritten to "Microsoft.Build.Framework, v12.0.0.0". The runtime seems to be failing to do this.

This used to work with xbuild 4.0 because xbuild was part of the framework, so its references were automatically "upgraded" like all framework assemblies.
Comment 7 Rodrigo Kumpera 2014-01-27 14:19:33 UTC
Working on it, I believe I got a small enough repro that will allow me to fix this quickly.
Comment 8 Rodrigo Kumpera 2014-01-27 16:39:56 UTC
Fixed in master and 3.2.7.
Comment 9 Mikayla Hutchinson [MSFT] 2014-01-27 18:38:21 UTC
Confirmed, I can now build fsharp on Mono master.