"JObject" and "JArray" ambiguous in the namespace Newtonsoft.Json.Linq

When I try to run my workflow I get these “validation errors”:

  • ‘JObject’ is ambiguous in the namespace ‘Newtonsoft.Json.Linq’.
  • ‘JArray’ is ambiguous in the namespace ‘Newtonsoft.Json.Linq’.
    The workflow does not show any validation errors before I try to run it.

My guess is that because I have several different packages dependent on different versions of Newtonsoft.Json, Uipath thinks JObject and JArray are ambiguous, but what do I do about it?

I saw that
" Invoke workflow file: Error compiling code error BC30560: ‘JTokenWriter’ is ambiguous in the namespace ‘Newtonsoft.Json.Linq’. At line 0"
was similar and was solved with a bug-fix.

@loginerror or @Mateus_Cruz is this something to be fixed?

What is your Studio version?

Studio 2019.10.1

@LB-Bemi
just for analysis reasons, can you try:

  • add Newtonsoft.Json to the imports
    grafik
  • in case of variable declarations, just use the entire path e.g. New Newtonsoft.Json…

Feel free to show us referenced dependecies of web activities, system.activities along with its reference configurations

I have found out that it only happens when I use the invoke code activity and pass an argument which is of type JObject or JArray.
I have found a workaround for my specific case.

@LB-Bemi
Perfect. May I ask to flag the solving post as solution or just give helping description on how you solved. Others can benefit from this

My workaround is that I found a way to do what I wanted without using the invoke code activity.
It should still be fixed in case the invoke code activity is necessary for ones workflow.

When using invoke code, it does not help to import Newtonsoft.Json or using the entire path to create a new object.

ok, in one case the fully qualifying of types for variable definitions helped me for stepping out from such issues. However you got it working and this is important. happy automation :+1:

Was that project of yours imported by another studio version by some way? do you have any errors if you create brand new project? Also do you mind to send us a screenshot of your project dependencies?

Nope, the error occurs as soon as I try to pass an argument of type JObject or JArray to an invoke code activity. Even if I begin a brand new project.

I have three packages (UiPath.System.Activities, UiPath.UIAutomation.Activities and UiPath.WebAPI.Activities) which have Newtonsoft.Json v. 11.0.2 as dependency and one non-standard package which has Newtonsoft.Json v. 12.0.2 as a dependency.

so you are using 2 versions of the same library… which package is using json 12.0.2?

The packages with dependency Newtonsoft.Json v. 11.0.2 should be using Newtonsoft.Json v. 12.0.2, so there should only be one version of Newtonsoft.Json.

what do you mean Should be using 12.0.2? every package has its own dependencies defined by the developer… if you end up installing packages that interfere with one another, this wont be a bug of an activity…

I have not installed several versions of Newtonsoft.Json.

When looking at my dependencies in studio, under the packages that need 11.0.2, the rectangle is a lighter blue, and when I mouse over it says: “Requested >= 11.0.2, resolved 12.0.2”.
I take this to mean that since I have 12.0.2, the three packages requesting 11.0.2 use 12.0.2 instead.

Also, I have no problem using JObject and JArray in all other activities. It is only a problem when using invoke code.

i tested like this with no error:
image

Did you have two packages which have different versions of Newtonsoft.Json as dependencies?
And did you try giving your invoke code an argument of type JObject?

i wouldn’t break my project on purpose, see my test:

Everything works fine if I delete the package which needs >=12.0.2.
But should it not be possible to use packages which need different versions of the same library?
Especially when the version they need is described as >= 11.0.2 and >=12.0.2 ?

well, that could happen but since packages are the way they are, we cant fight with them… if you really need the one that depends on 12.0.2, then try to remove manually the DLL for the 11.0.2 from your project to see if it works. Also remember that the activities in the packages are working, just invoke code dont have a way to force an specific version…