Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

F# 4.0 ReflectedDefinitions when compiling for F# 3.1 runtime #644

Closed
Tarmil opened this issue Sep 28, 2015 · 1 comment
Closed

F# 4.0 ReflectedDefinitions when compiling for F# 3.1 runtime #644

Tarmil opened this issue Sep 28, 2015 · 1 comment
Labels

Comments

@Tarmil
Copy link
Contributor

Tarmil commented Sep 28, 2015

In F# 4.0, with the ReflectedDefinition format change, assemblies that contain ReflectedDefinitions have an extra assembly-wide attribute CompilationMappingAttribute(string, System.Type[]). The problem is that even when compiling for an earlier runtime, this attribute is present (and I suspect the reflected definitions in general are using the new format? EDIT: actually I don't think so), despite that constructor being only defined in FSharp.Core 4.4.0.0. This means that the resulting assembly is invalid. The following program, compiled for the 3.1 runtime by the 4.0 compiler, raises an exception:

[<ReflectedDefinition>]
let dummy () = ()

[<EntryPoint>]
let rec main argv =
    System.Reflection.Assembly.GetExecutingAssembly().GetCustomAttributes(false)
    |> ignore
    0
Unhandled Exception: System.MissingMethodException: Method not found: 'Void Microsoft.FSharp.Core.CompilationMappingAttribute..ctor(System.String, System.Type[])'.
   at System.ModuleHandle.ResolveMethod(RuntimeModule module, Int32 methodToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount)
   at System.ModuleHandle.ResolveMethodHandleInternalCore(RuntimeModule module, Int32 methodToken, IntPtr[] typeInstantiationContext, Int32 typeInstCount, IntPtr[] methodInstantiationContext, Int32 methodInstCount)
   at System.ModuleHandle.ResolveMethodHandleInternal(RuntimeModule module, Int32 methodToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
   at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord, MetadataImport scope, Assembly& lastAptcaOkAssembly, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, Object[] attributes, IList derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, Boolean& isVarArg)
   at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent)
   at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeAssembly assembly, RuntimeType caType)
   at System.Reflection.RuntimeAssembly.GetCustomAttributes(Boolean inherit)
   at Program.main(String[] argv) in F:\TestCompilationMappingBug\TestCompilationMappingBug\Program.fs:line 6
@dsyme
Copy link
Contributor

dsyme commented Sep 29, 2015

Thanks for the report, this is indeed a bug in the compilation behaviour of the F# 4.0 compiler. The emit of this attribute here: https://github.com/Microsoft/visualfsharp/blob/9157d60b574484d3900f82d1eff76808e96637ce/src/fsharp/fsc.fs#L999 should be conditional in the same way as this: https://github.com/Microsoft/visualfsharp/blob/6a68e46d73763220cc9949e9540cbca0ecf9776a/src/fsharp/IlxGen.fs#L3298

dsyme added a commit to dsyme/fsharp that referenced this issue Sep 29, 2015
dsyme added a commit to dsyme/fsharp that referenced this issue Sep 29, 2015
@dsyme dsyme mentioned this issue Sep 29, 2015
@dsyme dsyme closed this as completed in 7514c29 Oct 10, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants