Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
vars-ecco opened this issue Aug 17, 2022 · 8 comments
Labels

Comments

@vars-ecco
Copy link

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?

@dsyme
Copy link
Contributor

dsyme commented Aug 17, 2022

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

@dsyme
Copy link
Contributor

dsyme commented Aug 17, 2022

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

@vars-ecco
Copy link
Author

@UnoSD
Copy link

UnoSD commented Aug 17, 2022

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

@dsyme
Copy link
Contributor

dsyme commented Aug 17, 2022

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
Copy link
Contributor

dsyme commented Aug 17, 2022

@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 dsyme closed this as completed Aug 17, 2022
@UnoSD
Copy link

UnoSD commented Aug 17, 2022

@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.

@vars-ecco
Copy link
Author

@dsyme works on my machine as well. thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants