Red Gate forums :: View topic - Problem when merging F# and C# assemblies
Return to www.red-gate.com RSS Feed Available

Search  | Usergroups |  Profile |  Messages |  Log in  Register 
Go to product documentation
SmartAssembly 6
SmartAssembly 6 forum

Problem when merging F# and C# assemblies

Search in SmartAssembly 6 forum
Post new topic   Reply to topic
Jump to:  
Author Message
ZachBray



Joined: 27 Mar 2012
Posts: 1

PostPosted: Tue Mar 27, 2012 4:43 pm    Post subject: Problem when merging F# and C# assemblies Reply with quote

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
Back to top
View user's profile Send private message
Brian Donahue



Joined: 23 Aug 2004
Posts: 6670

PostPosted: Wed Mar 28, 2012 5:44 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Simon C



Joined: 26 Feb 2008
Posts: 140
Location: Red Gate Software

PostPosted: Mon Apr 02, 2012 11:33 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Reply to topic All times are GMT + 1 Hour
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group