Newtonsoft JToken.Children Ambigouous Call Error
FunPlay3rs
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:

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

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
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:

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

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
0
Best 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 helps1
Answers
-
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 helps1 -
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!0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions