Options

Newtonsoft JToken.Children Ambigouous Call Error

FunPlay3rsFunPlay3rs Member Posts: 2
Hey,

I'm currently working on a Dynamic Json Reader.
For this I use the DotNet Class JToken from the Newtonsoft.Json DLL (Version 11.0.2).

But when I call the Function Children from the JToken Class I get this Error Message:
hp0bq7dbgpls.png

When I look into the Class in Visual Studio, I see that there is a overload of the Children Method.
mby3rtyf0s0b.png

But why does Dynamics don't know which Method it should take?
Does anyone already got something like this?

I have no Idea how to do this, without an custom DLL.



Kind Regards,
Dominic

Best Answer

  • Options
    ShaiHuludShaiHulud Member Posts: 228
    Answer ✓
    Had a similar issue recently and needed to first find the method specifically by name and parameters, and then execute it, using MethodInfo class
    Type := GETDOTNETTYPE(client);
    
    //Type2 := GETDOTNETTYPE(Irequest);
    //TypesArray2 := TypesArray2.CreateInstance(GETDOTNETTYPE(Type2),1);
    //TypesArray2.SetValue(Type2, 0);
    
    ParamsArray := ParamsArray.CreateInstance(GETDOTNETTYPE(Irequest),1);
    ParamsArray.SetValue(Irequest, 0);
    
    FOR i := 0 TO 60 DO BEGIN // could count them correctly using enumerator class, but it was 2am already when I wrote this
      MethodInfo := Type.GetMethods().GetValue(i);
      IF (MethodInfo.Name = 'Execute') THEN BEGIN
        BREAK;
      END;
    END;
    //MethodInfo := Type.GetMethod('Execute', TypesArray2); //this should work, but didn't in my case. if worked, you'd need to uncomment the previous comment block
    Iresponse := MethodInfo.Invoke(client,ParamsArray);
    

    Here are the variables (the important bits)
    Type	DotNet	System.Type.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
    TypesArray	DotNet	System.Array.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
    Type2	DotNet	System.Type.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
    TypesArray2	DotNet	System.Array.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
    ParamsArray	DotNet	System.Array.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
    MethodInfo	DotNet	System.Reflection.MethodInfo.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
    

    The idea:
    You declare the Type as the type of your JToken class. Then you create an .net array and put all your method parameters. Then search through all the methods available for the class, and if they match the name ("Children", in your case), break the loop and actually execute the method.

    Hope this helps

Answers

  • Options
    ShaiHuludShaiHulud Member Posts: 228
    Answer ✓
    Had a similar issue recently and needed to first find the method specifically by name and parameters, and then execute it, using MethodInfo class
    Type := GETDOTNETTYPE(client);
    
    //Type2 := GETDOTNETTYPE(Irequest);
    //TypesArray2 := TypesArray2.CreateInstance(GETDOTNETTYPE(Type2),1);
    //TypesArray2.SetValue(Type2, 0);
    
    ParamsArray := ParamsArray.CreateInstance(GETDOTNETTYPE(Irequest),1);
    ParamsArray.SetValue(Irequest, 0);
    
    FOR i := 0 TO 60 DO BEGIN // could count them correctly using enumerator class, but it was 2am already when I wrote this
      MethodInfo := Type.GetMethods().GetValue(i);
      IF (MethodInfo.Name = 'Execute') THEN BEGIN
        BREAK;
      END;
    END;
    //MethodInfo := Type.GetMethod('Execute', TypesArray2); //this should work, but didn't in my case. if worked, you'd need to uncomment the previous comment block
    Iresponse := MethodInfo.Invoke(client,ParamsArray);
    

    Here are the variables (the important bits)
    Type	DotNet	System.Type.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
    TypesArray	DotNet	System.Array.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
    Type2	DotNet	System.Type.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
    TypesArray2	DotNet	System.Array.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
    ParamsArray	DotNet	System.Array.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
    MethodInfo	DotNet	System.Reflection.MethodInfo.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
    

    The idea:
    You declare the Type as the type of your JToken class. Then you create an .net array and put all your method parameters. Then search through all the methods available for the class, and if they match the name ("Children", in your case), break the loop and actually execute the method.

    Hope this helps
  • Options
    FunPlay3rsFunPlay3rs Member Posts: 2
    ShaiHulud wrote: »
    Had a similar issue recently and needed to first find the method specifically by name and parameters, and then execute it, using MethodInfo class
    Type := GETDOTNETTYPE(client);
    
    //Type2 := GETDOTNETTYPE(Irequest);
    //TypesArray2 := TypesArray2.CreateInstance(GETDOTNETTYPE(Type2),1);
    //TypesArray2.SetValue(Type2, 0);
    
    ParamsArray := ParamsArray.CreateInstance(GETDOTNETTYPE(Irequest),1);
    ParamsArray.SetValue(Irequest, 0);
    
    FOR i := 0 TO 60 DO BEGIN // could count them correctly using enumerator class, but it was 2am already when I wrote this
      MethodInfo := Type.GetMethods().GetValue(i);
      IF (MethodInfo.Name = 'Execute') THEN BEGIN
        BREAK;
      END;
    END;
    //MethodInfo := Type.GetMethod('Execute', TypesArray2); //this should work, but didn't in my case. if worked, you'd need to uncomment the previous comment block
    Iresponse := MethodInfo.Invoke(client,ParamsArray);
    

    Here are the variables (the important bits)
    Type	DotNet	System.Type.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
    TypesArray	DotNet	System.Array.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
    Type2	DotNet	System.Type.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
    TypesArray2	DotNet	System.Array.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
    ParamsArray	DotNet	System.Array.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
    MethodInfo	DotNet	System.Reflection.MethodInfo.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
    

    The idea:
    You declare the Type as the type of your JToken class. Then you create an .net array and put all your method parameters. Then search through all the methods available for the class, and if they match the name ("Children", in your case), break the loop and actually execute the method.

    Hope this helps

    Wow, thanks!
    I already saw this solution on a site but I did not quite understand how I have to do it.
    But with your explanations I knew how to do it!
Sign In or Register to comment.