Bug 19044 - TypeLoadException when compiling mono
Summary: TypeLoadException when compiling mono
Status: NEW
Alias: None
Product: Runtime
Classification: Mono
Component: General (show other bugs)
Version: unspecified
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2014-04-14 17:05 UTC by Andres G. Aragoneses
Modified: 2015-05-08 23:03 UTC (History)
6 users (show)

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


Attachments

Description Andres G. Aragoneses 2014-04-14 17:05:21 UTC
When compiling mono master (and 3.4.0) in ARM hardfloat, I'm getting this exception:

Mono: Assembly Ref addref basic[0x2c4178] -> mscorlib[0x28dfb8]: 2
Mono: The class System.Func`3 could not be loaded, used in mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
 
Unhandled Exception:
System.TypeLoadException: Could not load type 'Mono.CSharp.CommandLineParser' from assembly 'basic, Version=3.4.0.0, Culture=neutral, PublicKeyToken=null'.
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeLoadException: Could not load type 'Mono.CSharp.CommandLineParser' from assembly 'basic, Version=3.4.0.0, Culture=neutral, PublicKeyToken=null'.
make[8]: *** [../../class/lib/build/tmp/mscorlib.dll] Error 1
make[8]: Leaving directory `/home/debian/monotest/mono-3.4.0/mcs/class/corlib'
make[7]: *** [do-all] Error 2
make[7]: Leaving directory `/home/debian/monotest/mono-3.4.0/mcs/class/corlib'
make[6]: *** [all-recursive] Error 1
make[6]: Leaving directory `/home/debian/monotest/mono-3.4.0/mcs/class'
make[5]: *** [all-recursive] Error 1
make[5]: Leaving directory `/home/debian/monotest/mono-3.4.0/mcs'
make[4]: *** [profile-do--build--all] Error 2
make[4]: Leaving directory `/home/debian/monotest/mono-3.4.0/mcs'
make[3]: *** [profiles-do--all] Error 2
make[3]: Leaving directory `/home/debian/monotest/mono-3.4.0/mcs'
make[2]: *** [all-local] Error 2
make[2]: Leaving directory `/home/debian/monotest/mono-3.4.0/runtime'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/debian/monotest/mono-3.4.0'
make: *** [all] Error 2


The message about not being able to load System.Func`3 is lacking lot of detail, and the culprit of this seems to be an error being swallowed by the runtime, here: 

https://github.com/mono/mono/blob/master/mono/metadata/class.c#L7110

mono_class_from_typeref() seems to be returning null there, and there is no error handling later.
Comment 1 Andres G. Aragoneses 2014-04-15 06:04:17 UTC
This call to mono_class_from_name() is returning NULL:

https://github.com/mono/mono/blob/master/mono/metadata/class.c#L266
Comment 2 Andres G. Aragoneses 2014-04-15 11:15:02 UTC
And it ends up here looking for System.Func`3:

https://github.com/mono/mono/blob/mono-3.4.0/mono/metadata/class.c#L7529
Comment 3 Zoltan Varga 2014-04-20 04:24:16 UTC
What is the version of the bootstrap mono, i.e. the mono version which is already on the system ?
Comment 4 John Lyon-Smith 2014-07-04 09:31:15 UTC
I also can no longer build the Mono from Git sources on Ubuntu.   I try to build using

	git clone git://github.com/mono/mono.git 
	cd mono
        git checkout mono-3.6.0-branch
	./autogen.sh --prefix=/usr/local
	make 

And I get the error:

...
mkdir -p -- ../../class/lib/build/
MCS     [build] mscorlib.dll

Unhandled Exception:
System.TypeLoadException: Could not load type 'Mono.CSharp.CommandLineParser' from assembly 'basic, Version=3.6.0.0, Culture=neutral, PublicKeyToken=null'.
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeLoadException: Could not load type 'Mono.CSharp.CommandLineParser' from assembly 'basic, Version=3.6.0.0, Culture=neutral, PublicKeyToken=null'.
make[8]: *** [../../class/lib/build/mscorlib.dll] Error 1
...

This also fails with master.

For a long while you have been able to build mono on a clean Ubuntu install without bootstrapping the system with an older Mono installation.  This is a serious regression in the Mono build environment and is  currently preventing many folks from deploying. 

Is there a workaround?
Comment 5 Zoltan Varga 2014-07-04 09:37:50 UTC
You can try make get-monolite-latest, that would download some bootstrap binaries.
Comment 6 John Lyon-Smith 2014-07-04 11:45:51 UTC
I just tried:

make get-monolite-latest
make

No luck.  The build still fails with the same error.  Help! :)
Comment 7 Andres G. Aragoneses 2014-07-04 11:49:32 UTC
When I had this problem (I'm no longer using the hardware I was using when I reported the bug), I recall a conversation I had with kumpera in the IRC channel about the mono runtime not propagating properly the real cause of the failure to load the type. He told me he had a WIP branch somewhere that was almost ready, which would improve things wrt this. You guys should ping him about this again.
Comment 8 Zoltan Varga 2014-07-04 12:05:17 UTC
Try a make distclean.
Comment 9 John Lyon-Smith 2014-07-04 18:16:21 UTC
#make distclean
Making distclean in m4
make[1]: Entering directory `/opt/mono/m4'
make[1]: *** No rule to make target `distclean'.  Stop.
make[1]: Leaving directory `/opt/mono/m4'
make: *** [distclean-recursive] Error 1

Then:

#make
Git submodules updated successfully
make  all-recursive
make[1]: Entering directory `/opt/mono'
Making all in po
make[2]: Entering directory `/opt/mono/po'
make[2]: *** No rule to make target `all'.  Stop.
make[2]: Leaving directory `/opt/mono/po'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/opt/mono'
make: *** [all] Error 2

No joy.
Comment 10 John Lyon-Smith 2014-07-05 08:42:57 UTC
OK, I finally found a simple solution that worked.  Firstly, I reverted to Ubuntu 12.04 (from 14.04). Then I ran:

	git clone git://github.com/mono/mono.git 
	cd mono
	apt-get install mono-runtime
	./autogen.sh --prefix=/usr/local
	make 
	apt-get remove mono-runtime
	make install 

And I have Mono 3.6.1 installed on Ubuntu 12.04.   I think later this I'll start migrating to openSUSE ;)
Comment 11 John Lyon-Smith 2014-09-04 02:57:42 UTC
Has there been any investigation done Mono team on this bug?  As far as I can determine Mono does not build on Ubuntu 14.04, which is a shame because that is the current LTS release.  If you need access to a clean Ubuntu 14.04 machine to investigate I would be happy to provide one.
Comment 12 Zoltan Varga 2014-09-04 15:55:49 UTC
These problems usually happen when the existing version of mono on the system, the one used to bootstrap the newer one, is too old.
Comment 13 John Lyon-Smith 2014-09-08 09:16:05 UTC
@zoltan, that is understandable.  I got Mono to build on Ubuntu 14.04 by doing an `apt-get install mono-complete` which installed 3.2.8.  Then I was able to do `git checkout mono-3.6.0; ./autoconf prefix=/usr/bin/local; make; make install`.

I could not get the HEAD of the Mono tree to build to build though.  This leads me to believe that "too old" could change quite rapidly, i.e. with minor point releases.   If that is the case, would it not be a really good idea to add a check either in autoconf or in make that the installed version of Mono is at least a certain version?
Comment 14 Zoltan Varga 2014-09-08 12:32:12 UTC
We do have checks but they could miss some changes.  If you have mono 3.6 installed, you can use that to bootstrap mono master instead of using 3.2.8 which might be too old.
Comment 15 Brandon White 2015-05-08 14:39:38 UTC
I cannot build the managed portion of any version later than 3.2.8 using 3.2.8.  Exact same errors as above.  I'm using a pcDuino3 (Allwinner A20).  I can build 3.2.8 just fine.

Using `make get-monolite-latest` for the bootstrap compiler doesn't help either.

I appears that the woes building armhf started in 3.4.0.

My next recourse is to try doing the managed build on an x86 system and then merge that back to my armhf system.  I'll report back.
Comment 16 Brandon White 2015-05-08 23:03:00 UTC
I can now confirm that I'm able to fully build 3.12.1 using an install of 3.12.1 that I merged together using the binaries from a native build (--disable-mcs-build) and the managed binaries from a build I did on a separate x64 system.

To summarize what I've learned about all this:  

- On armhf (specifically for me, the pcDuino3 using Allwinner A20), I can fully build both native and managed from the git branch mono-3.2.8.  This works fine not only with 3.2.8 installed from a package repo (eg Debian Jessie or Ubuntu 14.04), but also the much older but more widely available 2.10.8.1 (eg Debian Wheezy or Ubuntu 12.04)

- The same system cannot build git branch mono-3.4.0.  The native build is successful, but the managed build always fails for me for the issue described earlier in this report "System.TypeLoadException: Could not load type 'Mono.CSharp.CommandLineParser'" during the mscorlib.dll build.  I've observed this exact same problem with all subsequent release tags up to and including 3.12.1

- You can get a functioning mono install by merging the successful native build of 3.12.1 on your armhf system with the managed binaries from a successful build of some other system, say an x64 or x86 box.  This combined install is then able to fully build mono-3.12.1, both managed and unmanaged, and doesn't have the System.TypeLoadException problem when trying to build mscorlib.

This situation kind of stinks because neither Debian 7/Wheezy, Debian 8/Jessie, Ubuntu 12.04, nor Ubuntu 14.04 can lead you to building a mono version after and including 3.4.0.  To add further grief the Bootstrap version of get-monolite-latest does not appear to be capable of building >=3.4.0 either!

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