我正在尝试运行示例Vision API 项目。我基本上将代码复制并粘贴Program.cs
到我的应用程序中并执行它。
此行(即第 #36-#37行Program.cs
)
GoogleCredential credential = GoogleCredential.GetApplicationDefaultAsync().Result;
用. System.AggregateException
_ mscorlib.dll
_Additional information: One or more errors occurred.
通过检查InnerException
,我发现实际抛出的异常是InvalidOperationException
with Error deserializing JSON credential data.
。
尽管如此,我的云项目是一个基本项目,有一个服务帐户,并启用了 Cloud Vision API,仅此而已。我通过以下方式检查了我的环境变量是否设置为 JSON 文件:
Console.WriteLine(Environment.GetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS"));
在上面的行之前。的输出(就在崩溃之前)是(类似于):
C:\Users\me\Documents\Projects\MyProject\MyProject-ba31aae6efa1.json
我检查了文件,这是我启用服务帐户时得到的文件。其中的每个属性看起来都很好(即项目名称正确,路径正确,...)。
我安装了 Google Cloud SDK 并执行gcloud beta auth application-default login
并授权访问我的云帐户。
关于可能导致这种情况的任何想法?