I am trying to run the sample Vision API project. I basically copied and pasted the code Program.cs
into my application and executed it.
This line (which is line #36-#37 in Program.cs
)
GoogleCredential credential = GoogleCredential.GetApplicationDefaultAsync().Result;
throws a System.AggregateException
in mscorlib.dll
with Additional information: One or more errors occurred.
.
By examining InnerException
, I found out that the actual exception thrown is InvalidOperationException
with Error deserializing JSON credential data.
.
Nonetheless, my cloud project is a basic project, with a Service Account, and Cloud Vision API enabled, nothing else. I checked that my environment variable was set to the JSON file by writing:
Console.WriteLine(Environment.GetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS"));
before the line above. The output of that (just before the crash) is (something like):
C:\Users\me\Documents\Projects\MyProject\MyProject-ba31aae6efa1.json
I checked the file, and it is the file that I got when I enabled my service account. Every property in it looks fine (i.e. project name is correct, path's correct, ...).
I installed the Google Cloud SDK and executed gcloud beta auth application-default login
and authorized access to my cloud account.
Any ideas on what might be causing this?
By examining the detailed build log, I found out that the packages for the Google APIs had a dependency for Newtonsoft.Json
version 9.0.1
(the latest at the time of this writing).
For whatever reason, the Google APIs packages have a dependency (which is installed along with them) on Newtonsoft.Json
version 7.0.0
.
The packages came with the wrong version!
Installing the latest version (9.0.1
in this case) fixes the issue.