fsprojects / FSharp.TypeProviders.SDK

The SDK for creating F# type providers
https://fsprojects.github.io/FSharp.TypeProviders.SDK/
MIT License
298 stars 94 forks source link

Fix coreclr search for system.object #311

Closed KevinRansom closed 5 years ago

KevinRansom commented 5 years ago

@dsyme

The way we search for System.Object in the SDK is not complete. On Coreclr when using implementation assemblies the location of System.Object is: System.Private.CoreLib.dll.

mscorlib.dll, System.Runtime.dll and netstandard.dll all have type forwarders.

When using the FSharp.Data type provider on V 2.2.202 of the dotnet CLI I get this:

> #r @"C:\Users\kevinr\.nuget\packages\FSharp.Data\3.0.0\lib\netstandard2.0\FSharp.Data.dll"
-
- open FSharp.Data
-
- // Api Key = 93a2637fe6dad8426d128d5289325ca9
- open FSharp.Data
-
- type Weather = JsonProvider<"http://api.openweathermap.org/data/2.5/weather?id=2172797&APPID=93a2637fe6dad8426d128d5289325ca9">
- let apiUrl = "http://api.openweathermap.org/data/2.5/weather?id=2172797"
- let sf = Weather.Load(apiUrl + "&APPID=93a2637fe6dad8426d128d5289325ca9")
- let country = sf.Sys.Country
- let speed = sf.Wind.Speed
- let temp = sf.Main.Temp
- printfn "Temp for Australia is {%M}" temp;;

--> Referenced 'C:\Users\kevinr\.nuget\packages\FSharp.Data\3.0.0\lib\netstandard2.0\FSharp.Data.dll' (file may be locked by F# Interactive process)

  let sf = Weather.Load(apiUrl + "&APPID=93a2637fe6dad8426d128d5289325ca9")
  ---------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

stdin(10,10): error FS3033: The type provider 'ProviderImplementation.JsonProvider' reported an error in the context of provided type 'FSharp.Data.JsonProvider,Sample="http://api.openweathermap.org/data/2.5/weather?id=2172797&APPID=93a2637fe6dad8426d128d5289325ca9"', member 'Load'. The error: assembly mscorlib not found

>

This PR adds System.Private.Corlib to the list of dll names that may contain System.Object.

Output looks like:

> #r @"C:\Users\kevinr\.nuget\packages\FSharp.Data\3.0.0\lib\netstandard2.0\FSharp.Data.dll"
-
- open FSharp.Data
-
- // Api Key = 93a2637fe6dad8426d128d5289325ca9
- open FSharp.Data
-
- type Weather = JsonProvider<"http://api.openweathermap.org/data/2.5/weather?id=2172797&APPID=93a2637fe6dad8426d128d5289325ca9">
- let apiUrl = "http://api.openweathermap.org/data/2.5/weather?id=2172797"
- let sf = Weather.Load(apiUrl + "&APPID=93a2637fe6dad8426d128d5289325ca9")
- let country = sf.Sys.Country
- let speed = sf.Wind.Speed
- let temp = sf.Main.Temp
- printfn "Temp for Australia is {%M}" temp;;

--> Referenced 'C:\Users\kevinr\.nuget\packages\FSharp.Data\3.0.0\lib\netstandard2.0\FSharp.Data.dll' (file may be locked by F# Interactive process)

Temp for Australia is {299.32}
type Weather = FSharp.Data.JsonProvider<...>
val apiUrl : string =
  "http://api.openweathermap.org/data/2.5/weather?id=2172797"
val sf : FSharp.Data.JsonProvider<...>.Root =
  {
  "coord": {
    "lon": 145.77,
    "lat": -16.92
  },
  "weather": [
    {
      "id": 804,
      "main": "Clouds",
      "description": "overcast clouds",
      "icon": "04d"
    }
  ],
  "base": "stations",
  "main": {
    "temp": 299.32,
    "pressure": 1013,
    "humidity": 74,
    "temp_min": 297.59,
    "temp_max": 300.37
  },
  "visibility": 10000,
  "wind": {
    "speed": 8.7,
    "deg": 160
  },
  "clouds": {
    "all": 90
  },
  "dt": 1557802982,
  "sys": {
   ...
val country : string = "AU"
val speed : decimal = 8.7M
val temp : decimal = 299.32M
val it : unit = ()

Please Note: when this is merged and published … all of the existing TP's that want to successfully target the coreclr will need updating.

Thanks

Kevin

dsyme commented 5 years ago

Cool. I assume the test case for this is to use a type provider in F# Interactive on .NET Core? I may see if I can create one