rflechner / LinqToSalesforce

Presentation
https://rflechner.github.io/LinqToSalesforce/
The Unlicense
13 stars 8 forks source link

Error reading JObject from JsonReader #30

Open willsam100 opened 7 years ago

willsam100 commented 7 years ago

Description

Im getting the following error, but can't find what Im doing wrong

"The type provider 'ProviderImplementation.SalesforceProvider' reported an error: Error reading JObject from JsonReader. Current JsonReader item is not an object: StartArray. Path '', line 1, position 1." when use the SalesforceTypeProvider in visual studio code

Please provide a succinct description of your issue.

Repro steps

I have the following code:

r "../packages/Salesforce.TypeProvider/lib/LinqToSalesforce.dll"

r "../packages/Salesforce.TypeProvider/lib/LinqToSalesforce.TypeProvider.dll"

I @"../packages/Newtonsoft.Json/lib/net40"

r "Newtonsoft.Json.dll"

I "bin/debug/"

r "LinqToSalesforce.dll"

r "LinqToSalesforce.TypeProvider.dll"

open System open System.IO open System.Net open LinqToSalesforce open SalesforceProvider open Rest open Rest.OAuth

System.Net.ServicePointManager.ServerCertificateValidationCallback <- (fun -> true) ServicePointManager.SecurityProtocol <- SecurityProtocolType.Tls12 ||| SecurityProtocolType.Tls11

Environment.CurrentDirectory <- SOURCE_DIRECTORY let [] Authfile = @"/Users/sam.williams/Desktop/salesforce.json" let [] CacheFolder = SOURCE_DIRECTORY + "\.cache" // 200 minutes (if you don't change frequently your tables structures, then increase it) let [] SlidingExpiration = 200.

type TS = SalesforceTypeProvider<authFile=Authfile, instanceName="test", cacheFolder=CacheFolder, slidingExpirationMinutes=SlidingExpiration>

let authJson = File.ReadAllText Authfile let sf = TS(authJson, CacheFolder, (TimeSpan.FromMinutes SlidingExpiration))

salesforce.json: { "Clientid":"secret", "Clientsecret":"secret", "Securitytoken":"secret", "Username":"mysecrectusername", "Password":"mysecretpassword", "Instacename":"test" }

Expected behavior

Everything should compile with types,

Actual behavior

It doesn't compile and has an error listed above

Known workarounds

I can't find one

Related information

rflechner commented 6 years ago

Hi, could you look server responses with Fiddler ? ServicePointManager.SecurityProtocol has some issues with MONO. I think we should try to use .net core.

willsam100 commented 6 years ago

Quick update on this.

I tried with .net core, and I am getting the same error. I tried to find the find the API call response (using a Mac alternative, but could not find any api calls related to the salesforce type provider) ie inconclusive result.

willsam100 commented 6 years ago

Note that using dotnet build to build the project generates the following.

/Users/sam.williams/Projects/SalesForceTP/SalesForceTP/Program.fs(26,11): error FS3033: The type provider 'ProviderImplementation.SalesforceProvider' reported an error: Could not resolve field token 0x040000d6, due to: Could not load type of field '<StartupCode$LinqToSalesforce>.$Rest:settings@39' (1) due to: Could not load file or assembly 'Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. assembly:Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed type:<unknown type> member:<none> assembly:/Users/sam.williams/.nuget/packages/salesforce.typeprovider/1.0.0/lib/LinqToSalesforce.dll type:$Rest member:<none> [/Users/sam.williams/Projects/SalesForceTP/SalesForceTP/SalesForceTP.fsproj]

I attempted to get the the binding redirects with app.config to work, but could not find an easy win

tombardier commented 6 years ago

I'm having the same trouble, trying to use the example code provided. I've spent some time trying to figure it out, but I'm struggling. This is my oauth.json (sanitised):

{
    "ClientId":"sanitised",
    "ClientSecret":"sanitised",
    "SecurityToken":"sanitised",
    "Username":"sanitised",
    "Password":"sanitised"
}

I based this on the ImpersonationParam type in the code, here:

    type ImpersonationParam =
      { ClientId:string
        ClientSecret:string
        SecurityToken:string
        Username:string
        Password:string }
      static member FromJson json = 
Serialization.fromJson<ImpersonationParam> json

So, I removed the InstaceName (sic) from the example json

I'm using V2017 with .net framework 4.6.1. I have tried various things. I don't think it's getting as far as making any API calls, forgive me if I'm wrong. I just think it's a problem deserialising from the file, but I can't quite figure it out. I'm learning F#, and have worked with Salesforce in python quite a lot, so I thought this would be a good thing to try and use to learn with. Thank you for any assistance!

sftypeprovider_problem

tombardier commented 6 years ago

I spent a bit of time putting together a simple json deserialising step to show that my json should deserialise in to the ImpersonationParam type cleanly. I'm not using the NewtonSoft json stuff that you do, it looks complicated! I've used FSharp.Json. I've copied and pasted the ImpersonationParam type from the LinqToSalesforce code, and then shown that my json deserialises in to it.

simpledeserialise deserialised_output

tombardier commented 6 years ago

In case it's of any assistance in reproducing the bug (rather than a screenshot of my code):

open Deedle
open System
open FSharp.Charting
open XPlot
open XPlot.Plotly
open System
open System.IO
open System.Net
open LinqToSalesforce
open SalesforceProvider
open Rest
open Rest.OAuth

ServicePointManager.SecurityProtocol <- SecurityProtocolType.Tls12 ||| SecurityProtocolType.Tls11

Environment.CurrentDirectory <- __SOURCE_DIRECTORY__
let [<Literal>] authfile = __SOURCE_DIRECTORY__ + "\\oauth.json"
let [<Literal>] cacheFolder = __SOURCE_DIRECTORY__ + "\\.cache"
let [<Literal>] slidingExpiration = 200.
type TS = SalesforceTypeProvider<
            authFile=authfile, instanceName="login", 
            cacheFolder=cacheFolder, slidingExpirationMinutes=slidingExpiration>

let authJson = File.ReadAllText authfile
let sf = TS(authJson, cacheFolder, (TimeSpan.FromMinutes slidingExpiration))

[<EntryPoint>]
let main argv = 
    printfn "%A" argv
    0 // return an integer exit code
tomboland commented 6 years ago

I've attempted to set the same thing up in Mono, runing on linux. Basically the same code. I still get the same error as with the Windows Vs2017 solution, but in addition, I'm seeing this, and I'm not sure how to resolve the dependency?

/home/tom.boland/Projects/LinqSf/LinqSf/Program.fs(11,11): Error FS3033: The type provider 'ProviderImplementation.SalesforceProvider' reported an error: Could not resolve field token 0x040000d6, due to: Could not load type of field '<StartupCode$LinqToSalesforce>.$Rest:settings@39' (1) due to: Could not load file or assembly 'Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. assembly:Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed type: member:(null) signature: assembly:/home/tom.boland/Projects/LinqSf/packages/Salesforce.TypeProvider.1.0.0/lib/LinqToSalesforce.dll type:$Rest member:(null) signature: (FS3033) (LinqSf)