【发布时间】:2017-04-18 14:23:24
【问题描述】:
有没有办法在 Azure Functions 中使用 Google.Cloud.BigQuery.V2 (1.0.0-beta10) API?
我喜欢在 Azure Functions 中使用此 API 和我的 C# 代码,但收到此错误:
error CS0103: The name 'BigQueryClient' does not exist in the current context
error CS0246: The type or namespace name 'BigQueryTable' could not be found (are you missing a using directive or an assembly reference?)
error CS0246: The type or namespace name 'BigQueryJob' could not be found (are you missing a using directive or an assembly reference?)
error CS0246: The type or namespace name 'CreateQueryJobOptions' could not be found (are you missing a using directive or an assembly reference?)
error CS0246: The type or namespace name 'BigQueryResults' could not be found (are you missing a using directive or an assembly reference?)
error CS0246: The type or namespace name 'GetQueryResultsOptions' could not be found (are you missing a using directive or an assembly reference?)
Compilation failed.
在我的 project.json 中,我有以下代码:
{
"frameworks": {
"net46":{
"dependencies": {
"Google.Cloud.BigQuery.V2": "1.0.0-beta10"
}
}
}
}
我认为 API 在 .NET 版本 4.5 中,而 Azure Functions 需要 4.6。所以好像没有办法在AF中使用这个API? 我也用“net45”尝试过,但得到了同样的错误。
更新:此 API 正在处理 AF(另请参阅下面的评论)。编译成功。但是由于缺少凭据,我的功能仍然无法正常工作。在我的 Visual Studio 中,代码运行正常,但在 AF 中出现以下错误:
Exception while executing function: Functions.TimerTriggerCSharp1. mscorlib: Exception has been thrown by the target of an invocation. Google.Api.Gax: The Application Default Credentials are not available. They are available if running in Google Compute Engine. Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the credentials. See https://developers.google.com/accounts/docs/application-default-credentials for more information.
我已经生成了一个服务帐户密钥作为 json 文件并上传到我的 AF。通常,我认为,通过在我的 C# 代码中了解项目和数据集 ID,我可以访问我在 BigQuery 上的表:
string projectId = "...";
string datasetId = "...";
var client = BigQueryClient.Create(projectId);
List<BigQueryTable> tables = client.ListTables(datasetId).ToList();
【问题讨论】:
-
包目标很好,可以在net46上工作。你能分享你的代码吗?你看到包恢复过程发生了吗?你是不是偶然部署了 project.lock.json 文件?
-
感谢您的评论。我不知道为什么,但几分钟后它就没有这些错误。编译成功。但是由于缺少凭据,我的功能仍然无法正常工作。我会更新我的问题。
标签: .net api azure google-bigquery azure-functions