Bug 15124 - TypeLoadException when resolving qualified names of generic, compiler-generated F# types
Summary: TypeLoadException when resolving qualified names of generic, compiler-generat...
Status: RESOLVED FIXED
Alias: None
Product: Runtime
Classification: Mono
Component: Reflection ()
Version: 3.0.x
Hardware: All All
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2013-10-02 06:25 UTC by Eirik Tsarpalis
Modified: 2013-11-14 12:33 UTC (History)
5 users (show)

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


Attachments
Source code to a program that reproduces the problem (334 bytes, text/plain)
2013-10-02 06:25 UTC, Eirik Tsarpalis
Details


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:
Status:
RESOLVED FIXED

Description Eirik Tsarpalis 2013-10-02 06:25:15 UTC
Created attachment 5038 [details]
Source code to a program that reproduces the problem

The F# compiler generates large amounts of internal types that are used for encoding things like closures of lambda terms.  Such types are identifiable by names like "foo@6-3[System.Int32]". There seems to be an issue with the mono runtime that has to do with type loading of such compiler-generated types, as long as they are generic. In particular, trying to call the 'Type.GetType' method on the assembly qualified name of such a type results in a TypeLoadException:

System.TypeLoadException: Could not load type 'FSI_0005+pow@40-3[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], FSI-ASSEMBLY, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.
  at (wrapper managed-to-native) System.Type:internal_from_name (string,bool,bool)
  at System.Type.GetType (System.String typeName, Boolean throwOnError) [0x00000] in <filename unknown>:0 
  at <StartupCode$FSI_0017>.$FSI_0017.main@ () [0x00000] in <filename unknown>:0 
  at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
  at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0 
Stopped due to error

This behavior is observable in both compiled F# code and F# interactive scripts. I attach a file that reproduces the former case. In the fsharpi, one can reproduce the issue as follows:

// F# code
open System

let rec pow f n =
    if n = 0 then id
    else
        pow f (n-1) << f

let f = pow (fun x -> x + 1) 10

let t = f.GetType()

// TypeLoadException
Type.GetType(t.AssemblyQualifiedName, true)
Comment 1 Eirik Tsarpalis 2013-11-04 15:05:18 UTC
Issue persists in mono 3.2.3
Comment 2 Rodrigo Kumpera 2013-11-14 12:33:57 UTC
Fixed in master, will be part of mono 3.2.6