Problem when merging F# and C# assemblies

ZachBrayZachBray Posts: 2
edited April 2, 2012 6:33AM in SmartAssembly
Hi all,

I am experiencing a problem when I try to merge F# and C# assemblies with each other.

The basic problem scenario...

Given I have merged a C# assembly with F# dependencies
When I reference the merged assembly from another F# project
And I try to open a module
Then F# cannot open the module
And sees the type as a class

I found a partial fix by applying an attribute but it has another unwanted side effect...

Given I have merged a C# assembly with F# dependencies
And the C# assembly has this attribute:
[assembly:FSharpInterfaceDataVersion(2, 0, 0)]
When I reference the merged assembly from another F# project
And I try to open a module
Then F# can open the module

However...

Given I have merged a C# assembly with F# dependencies
And the C# assembly has this attribute:
[assembly:FSharpInterfaceDataVersion(2, 0, 0)]
When I reference the merged assembly from another F# project
And I try to use a type defined in C#
Then F# cannot see the type

Is there any way to get this working nicely? Unfortunately, I have a suspicion that it might be to do with the way the F# compiler is treating the assemblies with the attribute mentioned above.

Zach

Comments

  • Brian DonahueBrian Donahue Posts: 6,590 Bronze 1
    Hi Zach,

    If merging doesn't work, there is usually precious little you can do about it and you should use embedding instead.

    I'm guessing the problem is F# needs that assembly-level attribute and it disappears when the assembly is merged. You can verify that with Reflector or a similar tool.
  • What you're trying to do is produce an API on a dll using several input assemblies. Furthermore, the two dlls are compiled using different languages. As you may imagine, this can lead to some unusual results.

    Now, .NET is meant to be language-agnostic, but there's obviously some extra metadata on the F# assembly that's required to consume it properly from F#.

    My guess is that the F# compiler can only deal with an assembly written in one language - it either treats a dll as C#/VB, or F#, and it uses the FSharpInterfaceDataVersion assembly-level attribute to distinguish the two. Because you've got types from two different languages in the same assembly, the compiler is getting confused, because it either tries to treat F# types as C#, or C# types as F#, it can't mix it.

    This looks like a limitation of the F# compiler. If you want this fixed, you could ask the F# team to specify FSharpInterfaceDataVersion on a per-type basis, rather than per-assembly.
Sign In or Register to comment.