Skip to content

Incorrect FSharp.Core version is used when a type provider is active #2399

Closed

Description

@allykzam

Working with an existing project that has a reference to FSharp.Core version 4.4.0.0 from the NuGet package, the project compiles with a reference to version 4.4.1.0 when a type provider is in use.

Repro steps

Provide the steps required to reproduce the problem

  1. Create a new F# project, and manually edit the project file to remove the reference to FSharp.Core.
  2. Add NuGet package references to FSharp.Core package 4.0.0.1, and any type provider -- I am using the FSharp.Configuration package in my sample.
  3. Make use of the type provider
  4. Compile the project
  5. Using ILSpy or similar, validate the version of FSharp.Core referenced by the project output

Expected behavior

As the project file indicates that FSharp.Core version 4.4.0.0 should be used, and includes a <HintPath> node indicating where to find it, the specified copy of FSharp.Core should be used.

Actual behavior

After making use of a type provider, the compiled output of the project references FSharp.Core version 4.4.1.0.

Known workarounds

Use Visual Studio 2015

Related information

As an additional point, adjusting the <TargetFSharpCoreVersion> has no affect.

  • Windows 10 x86_64
  • "Latest" Visual Studio 2017 RC version 15.0.0-RC.4+26206.0
  • Visual F# Tools version 15.4.1.17020301 installed via the download on GitHub
  • Sample project file and source files are attached; this is the smallest repro I found that shows this. Commenting-out or uncommenting the TestConfig type defined in Library1.fs and rebuilding the project causes the output library to change which version of FSharp.Core it references.

FSharpCore Repro.zip

Activity

  1. smoothdeveloper commented on Feb 9, 2017

    @smoothdeveloper
    Contributor

    @amazingant I've noticed something similar when first trying VS2017 but couldn't identify the root cause, thanks a lot for your analysis and case reproduction.

  2. allykzam commented on Feb 9, 2017

    @allykzam
    Author

    @smoothdeveloper I'm just [surprised/pleased] I was able to narrow this down to "comment out this line of code" so quickly

  3. KevinRansom commented on Feb 10, 2017

    @KevinRansom
    Contributor

    I will take a look at this over the weekend.

    However ... my suspicion is it's a bug in theTypeProvider ... I think that at some point the TP returns a Type object from FSharp.Core and in order to get that type object it uses the ambient FSharp.Core (Either Type.GetType() or typeof<>) rather than use the fsharp.core passed on the command line by the compiler.

    The compiler then sees a reference to an FSharp.Core.dll that is higher than any it has seen before and unifies the references up. We discussed and then discarded the notion of having the compiler map known types in favor of the TP taking care of it. This is actually a big issue with TP's and why every TP has a providedtypes.fs file where it can be localized and systematized.

    Back in the day the compiler would emit references to both versions of fsharp.core.dll's and even worse things happened.

    Anyway that is my suspicion, it will take a while

  4. allykzam commented on Feb 13, 2017

    @allykzam
    Author

    @KevinRansom I cannot speak for the FSharp.Configuration type provider, but testing against my own internal type provider, is there a reference point somewhere as to how to find the fsharp.core passed on the command line by the compiler as you mentioned? I will poke around and try to find it myself. Hopefully I can resolve this in my internal type provider, and open an issue for FSharp.Configuration.

  5. allykzam commented on Feb 13, 2017

    @allykzam
    Author

    @KevinRansom Quick follow-up, found a version of FSharp.Core specified in the ReferencedAssemblies property of the TypeProviderConfig value passed to my type provider; will attempt to update my code to use the assembly specified there.

  6. allykzam commented on Feb 13, 2017

    @allykzam
    Author

    @KevinRansom Have managed to come up with a simpler test case by adjusting the TP; I created a static property that returns an empty string, and adjusted the consuming project to only reference that property. After rebuilding, the consuming project references version 4.4.0.0 as expected. If I change out the provided property's GetterCode with (fun _ -> <@@ let x = [| ""; "" |] in x.[0] @@>), the reference goes back to 4.4.1.0.

    Assuming it is somewhere in the IL emitting code, I also tried (fun _ -> <@@ System.Linq.Enumerable.First([| ""; "" |]) @@>) which gave me 4.4.0.0, and (fun _ -> <@@ [| ""; "" |] |> System.Linq.Enumerable.First @@>) which gave me 4.4.1.0. I can try to narrow down which types of expressions work if that helps.

  7. petertiedemann commented on Mar 8, 2017

    @petertiedemann

    I am also seeing this in the released VS 2017.

  8. KoenigLear commented on Apr 5, 2017

    @KoenigLear

    I can also reproduce it on 26228.12 Could not load file or assembly 'FSharp.Core, Version=4.4.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
    myproj.fsproj.txt

  9. dsyme commented on May 9, 2017

    @dsyme
    Contributor

    @amazingant Right now the type provider be adjusted to be a properly cross-targeting type provider

    The code necessary to do this is in the Type Provider starter Pack but is not particularly well-documented. It is also only designed for erasing type providers

  10. dsyme commented on Jun 22, 2017

    @dsyme
    Contributor

    This is a duplicate of #3049 (it is also by design - the type provider needs to be adjusted)

  11. allykzam commented on Jun 22, 2017

    @allykzam
    Author

    @dsyme Understood. Is it possible for some of the documentation around type providers to be adjusted to point this out and highlight how easy it is to run into? This is the single reason that I cannot open any of my work projects in VS 2017, until management gives me time to go back and adjust our internally-developed type providers and update third-party ones.

    It was easy enough for me to get that using types from FSharp.Core in the wrong place trigger this behavior, but it seemed a bit of a stretch to just assume that syntactic sugar like pipelining would also be a problem. And yet, pipelining also triggers this behavior -- unless you use a generative type provider, which optimizes out the |> operator. Bit of a minefield to deal with if one is not already aware of what a cross-targeting type provider is, and has just followed the MSDN tutorial.

  12. dsyme commented on Jun 22, 2017

    @dsyme
    Contributor

    @amazingant Yes, it's a significant overall issue. We need to revamp type provider docs for .NET Core too.

    Probably the best place to add a tracking issue for type provider docs and basic SDK issues is in https://github.com/fsprojects/FSharp.TypeProviders.StarterPack/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions