You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Incorrect FSharp.Core version is used when a type provider is active #2399
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
Create a new F# project, and manually edit the project file to remove the reference to FSharp.Core.
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.
Make use of the type provider
Compile the project
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.
@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.
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.
@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.
@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.
@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.
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
@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
@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.
Activity
smoothdeveloper commentedon Feb 9, 2017
@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.
allykzam commentedon Feb 9, 2017
@smoothdeveloper I'm just [surprised/pleased] I was able to narrow this down to "comment out this line of code" so quickly
KevinRansom commentedon Feb 10, 2017
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
allykzam commentedon Feb 13, 2017
@KevinRansom I cannot speak for the
FSharp.Configurationtype provider, but testing against my own internal type provider, is there a reference point somewhere as to how to find thefsharp.core passed on the command line by the compileras 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 forFSharp.Configuration.allykzam commentedon Feb 13, 2017
@KevinRansom Quick follow-up, found a version of
FSharp.Corespecified in theReferencedAssembliesproperty of theTypeProviderConfigvalue passed to my type provider; will attempt to update my code to use the assembly specified there.allykzam commentedon Feb 13, 2017
@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.0as expected. If I change out the provided property'sGetterCodewith(fun _ -> <@@ let x = [| ""; "" |] in x.[0] @@>), the reference goes back to4.4.1.0.Assuming it is somewhere in the IL emitting code, I also tried
(fun _ -> <@@ System.Linq.Enumerable.First([| ""; "" |]) @@>)which gave me4.4.0.0, and(fun _ -> <@@ [| ""; "" |] |> System.Linq.Enumerable.First @@>)which gave me4.4.1.0. I can try to narrow down which types of expressions work if that helps.petertiedemann commentedon Mar 8, 2017
I am also seeing this in the released VS 2017.
KoenigLear commentedon Apr 5, 2017
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
dsyme commentedon May 9, 2017
@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
dsyme commentedon Jun 22, 2017
This is a duplicate of #3049 (it is also by design - the type provider needs to be adjusted)
allykzam commentedon Jun 22, 2017
@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 across-targeting type provideris, and has just followed the MSDN tutorial.dsyme commentedon Jun 22, 2017
@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/