I have created an F# library using the standard F# Portable Library option provided by VS2012 when creating a new project. The library is intended to be used by a C# program.
The F# library needs to accept data from the C# app that is encapsulated in a C# object. I have imported the C# dll containing the object into the F# library but get the following 2 errors:
The primary reference "DataStructures" could not be resolved because it has an indirect dependency on the framework assembly "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" which could not be resolved in the currently targeted framework. ".NETPortable,Version=v4.0,Profile=Profile47". To resolve this problem, either remove the reference "DataStructures" or retarget your application to a framework version which contains "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089".
and
The primary reference "DataStructures" could not be resolved because it has an indirect dependency on the framework assembly "System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" which could not be resolved in the currently targeted framework. ".NETPortable,Version=v4.0,Profile=Profile47". To resolve this problem, either remove the reference "DataStructures" or retarget your application to a framework version which contains "System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089".
In looking through the messages it is clear that there is a version incompatibility issues between mscorlib and System used in the F# and C# dlls. So I naively switched the F# references to the exact ones used by the C# dll. This momentarily resolved my error but as soon as I built it, the f# library's references were automatically switched back to their previous "portable" versions of mscorlib and System.
I can get around this by forcing the C# app to turn its data into Tuple<'t> before sending it to the f# dll and thus get rid of the C# dll dependency in this project, but I was hoping to avoid these transformations.
There is a post here
base CLI library 'mscorlib' is binary-incompatible with the referenced F# core library which suggests pass explicit references to both on the command-line.
Is there some way to do this is an F# Portable Library? Or is there so other way to resolve these compatibility issues?
Edit: I have also checked that:
- Both dlls are targeting .net 4.5
- Both dlls' build options are set to standard "any cpu" settings
F# Portable Libraryas opposed to theF# librarybecause I thought it was the library of choice if you wanted it to function in a c# app. Visual studio labels it asA F# library that can run on Windows and SilverlightHave I misunderstood this? - Chris TarnF# library. The portable one targets the .NET portable runtime, but the standard F# library should target the same .NET that C# targets by default. - John Palmer