FSharp.Data icon indicating copy to clipboard operation
FSharp.Data copied to clipboard

The design-time type 'FSharp.Data.Runtime.StructuralInference+InferenceMode' utilized by a type provider was not found

Open vars-ecco opened this issue 1 year ago • 3 comments

Hello,

Today I started getting this error when running a script.

Project.fsproj.fsx(12,1): error FS3033: The type provider 'ProviderImplementation.JsonProvider' reported an error: The design-time type 'FSharp.Data.Runtime.StructuralInference+InferenceMode' utilized by a type provider was not found in the target reference assembly set

And I saw there was a new release of the library, 5.0.1 when I specified previous version, #r "nuget: FSharp.Data,4.2.9", it started working again.

I use JsonProvider like this

type Auth = JsonProvider<const(__SOURCE_DIRECTORY__ + "/samples/auth.json")>

Were there some breaking changes, and how should I use json type provider now?

vars-ecco avatar Aug 17 '22 10:08 vars-ecco

I see, thank you. I will unlist the package and get this fixed

dsyme avatar Aug 17 '22 11:08 dsyme

@vars-ecco Do you have a minimal repro script please, with information on how you run it? Thank you

dsyme avatar Aug 17 '22 11:08 dsyme

@dsyme please see here https://github.com/vars-ecco/ErrorSample

vars-ecco avatar Aug 17 '22 11:08 vars-ecco

same problem here; this is the code (non-minimal):

#r "nuget: FSharp.Data"
#r "System.Xml.Linq.dll"

open System
open System.Globalization
open FSharp.Data

[<Literal>]
let path = __SOURCE_DIRECTORY__ + "/ALL.xhb"

type ExchangeRateApiGbp =
    JsonProvider<"https://open.er-api.com/v6/latest/GBP">

type ExchangeRateApiUsd =
    JsonProvider<"https://open.er-api.com/v6/latest/USD">

let gbpToEur =
    ExchangeRateApiGbp.GetSample().Rates.Eur

let usdToEur =
    ExchangeRateApiUsd.GetSample().Rates.Eur

type YahooFinanceMsft =
    JsonProvider<"https://query1.finance.yahoo.com/v8/finance/chart/MSFT">

let currentMsftStockPrice =
    YahooFinanceMsft.GetSample().Chart.Result[0].Meta.RegularMarketPrice

let currencySymbol =
    [ "EUR", "€"
      "USD", "$"
      "GBP", "£"
      "MSF", "S" ]
    |> Map.ofList

type HomeBank = XmlProvider<path>

try
    let data = HomeBank.GetSample()

    let accounts =
        data.Accounts
        |> Array.map (fun a -> a.Key, a)
        |> Map.ofArray

    let currencies =
        data.Curs
        |> Array.map (fun a -> a.Key, a)
        |> Map.ofArray

    let zpn =
        Environment.GetEnvironmentVariable("ZOOPLA_PROPERTY_NUMBER")

    let currentPropertyEstimateGbp =
        Http.RequestString($"https://www.zoopla.co.uk/property/uprn/{zpn}/", headers = [ "user-agent", "curl/7.84.0" ])
        |> HtmlDocument.Parse
        |> HtmlDocument.descendants false (fun n -> n.HasId("property-estimate"))
        |> Seq.exactlyOne
        |> HtmlNode.descendants false (fun n -> n.HasAttribute("data-testid", "estimate-blurred"))
        |> Seq.exactlyOne
        |> HtmlNode.innerText
        |> (fun s -> s.Replace("£", "").Replace(",", ""))
        |> Decimal.Parse

    // Put all accounts in a summary
    let allAccountSummaries =
        data.Opes
        |> Array.groupBy (fun o -> o.Account)
        |> Array.map (fun (a, o) -> accounts[a], o)
        |> Array.map (fun (a, o) -> a.Name, (o |> Array.sumBy (fun oi -> oi.Amount)) + a.Initial, currencies[a.Curr].Iso)

    // Put all (add property estimate) and convert currency as main label (EUR net worth)
    let netWorth =
        allAccountSummaries
        |> Array.sumBy (fun r -> match r with
                                 | "Fidelity (vested)"  , amount, _     -> amount * currentMsftStockPrice * usdToEur
                                 | "Fidelity (unvested)", _     , _     -> 0m
                                 | _                    , amount, "EUR" -> amount
                                 | _                    , amount, "GBP" -> amount * gbpToEur
                                 | _                                    -> failwith "Unsupported currency")
        |> (fun x -> x + (currentPropertyEstimateGbp * gbpToEur))
    
    let maxAccountNameLength =
        allAccountSummaries
        |> Array.map (fun (name, _, _) -> name.Length)
        |> Array.max
    
    let formatName (name : string) =
        name.Replace(" (EUR)", "").Replace(" (GBP)", "").PadRight(maxAccountNameLength)
    
    let formatAmount (amount : decimal) currency =
        let defaultPadding = 13
        
        let format (amount : decimal) (locale : string) padding =
            String.Format(CultureInfo(locale), "{0:c}", amount).PadRight(padding)
        
        match currency with
        | "USD" -> $"""{format amount "en-US" defaultPadding} ({format (amount * usdToEur) "it-IT" 0})"""
        | "EUR" -> $"""{format amount "it-IT" defaultPadding}"""
        | "GBP" -> $"""{format amount "en-GB" defaultPadding} ({format (amount * gbpToEur) "it-IT" 0})"""
        | "MSF" -> $"""{($"{amount:f2} shares".PadRight(defaultPadding))} ({format (amount * currentMsftStockPrice * usdToEur) "it-IT" 0})"""
        | _     -> failwith "Unsupported currency"
    
    let tooltip =
        allAccountSummaries
        |> Array.sortByDescending (fun (_, amount, _) -> amount)
        |> Array.map (fun (name, amount, currency) -> $"""{formatName name} {formatAmount amount currency}""")
        |> String.concat "\n"

    $"""
    <txt> €{netWorth:n0} </txt>
    <txtclick>homebank</txtclick>
    <tool><tt>{tooltip}</tt></tool>
    """
    |> printfn "%s"
with ex ->
    $"""
    <txt> Error </txt>
    <txtclick>zenity --error --no-wrap --text="{ex.StackTrace}"</txtclick>
    <tool>{ex.Message}</tool>
    """
    |> printfn "%s"

that works on another person's machine.

if I pin the version (even to the latest #r "nuget: FSharp.Data, 4.2.10") it works, if I omit it, I get the same error as above.

pinning is a good workaround for me, sharing the details to help resolve.

thanks

UnoSD avatar Aug 17 '22 12:08 UnoSD

Sigh. Frustratingly unlisting a package doesn't seem to stop nuget from resolving it.

I'll push a 5.0.2 with the package split undone, then work to find a resolution

dsyme avatar Aug 17 '22 12:08 dsyme

@UnoSD @vars-ecco I have fixed the problem (via a workaround) and 6.0.1-beta001 is published.

Could I ask you a favour to try this version with your scripts on your machines? I've tried yours @UnoSD and it Works On My Machine ™️

Thanks

dsyme avatar Aug 17 '22 17:08 dsyme

@dsyme yep, works well on mine, too. I think the latest (then unlisted, I presume) version was downloaded and cached, hence why it wasn't working and I had to pin. thanks.

UnoSD avatar Aug 17 '22 17:08 UnoSD

@dsyme works on my machine as well. thanks!

vars-ecco avatar Aug 17 '22 19:08 vars-ecco