Problem when merging F# and C# assemblies

.NET obfuscator and automated error reporting

Moderators: Luke Jefferson, melvyn.harbour, dom.smith

Problem when merging F# and C# assemblies

Postby ZachBray » Tue Mar 27, 2012 4:43 pm

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
ZachBray
 
Posts: 1
Joined: Tue Mar 27, 2012 4:29 pm

Postby Brian Donahue » Wed Mar 28, 2012 5:44 pm

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.
Brian Donahue
 
Posts: 6668
Joined: Mon Aug 23, 2004 10:48 am

Postby Simon C » Mon Apr 02, 2012 11:33 am

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.
Simon C
 
Posts: 140
Joined: Tue Feb 26, 2008 4:56 pm
Location: Red Gate Software


Return to SmartAssembly 6

Who is online

Users browsing this forum: No registered users and 0 guests