Repository navigation
Closed
Labels
Description
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
0Unhandled 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
Activity
dsyme commentedon 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
Fix dotnet#644
Fix dotnet#644 ()