c# - 在 Azure Functions 上使用 AdWords API

标签 c# .net azure azure-functions google-ads-api

我正在尝试创建一个使用 AdWords API 的 Azure 函数。我现在的代码工作正常,我所要做的就是让函数按给定的时间间隔运行。 但是,当我尝试在本地运行该函数时,我收到以下错误消息:

[22-Jun-18 19:08:58] Executed 'KeywordPlanner' (Failed, Id=ab7c3ecf-1238-4370-ab5b-17d547d354b3)
[22-Jun-18 19:08:58] System.Private.CoreLib: Exception while executing function: KeywordPlanner. System.Configuration.ConfigurationManager: Configuration system failed to initialize. System.Configuration.ConfigurationManager: Unrecognized configuration section system.serviceModel. (C:\Users\frede\AppData\Local\Azure.Functions.V2.Cli\func.dll.config line 204)

如果我尝试上传该函数并运行它,我会收到此错误:

2018-06-22T18:50:35  Welcome, you are now connected to log-streaming service.
2018-06-22T18:50:40.967 [Information] Executing 'KeywordPlanner' (Reason='This function was programmatically called via the host APIs.', Id=321756f7-3cf1-4235-a741-daf97d304058)
2018-06-22T18:50:40.972 [Error] System.Private.CoreLib: Exception while executing function: KeywordPlanner. Google.AdWords: Could not load file or assembly 'System.Private.ServiceModel, Version=4.1.2.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified. System.Private.CoreLib: Could not load the specified file.
2018-06-22T18:50:41.039 [Error] Executed 'KeywordPlanner' (Failed, Id=321756f7-3cf1-4235-a741-daf97d304058)

我使用的是 .NET Standard 2.0。

我该如何修复此错误并让我的函数运行?

更新:

在 Jerry Liu 的帮助下解决问题后,我收到以下错误:

2018-06-25T07:43:20.517 [Error] System.Private.CoreLib: Exception while executing function: KeywordPlanner. System.Net.Http.WinHttpHandler: WinHttpHandler is only supported on .NET Framework and .NET Core runtimes on Windows. It is not supported for Windows Store Applications (UWP) or Unix platforms.
2018-06-25T07:43:20.679 [Error] Executed 'KeywordPlanner' (Failed, Id=4231f32f-f83f-4f37-99a7-b90484933e2f)

最佳答案

更新

问题现在正在跟踪here 。运行时文件夹中的程序集[FunctionProject]\bin\Debug\netcoreapp2.1\bin\runtimes没有加载到函数上下文中。

在@Adrian的帮助下,发现了问题WinHttpHandler is only supported on .NET Framework and .NET Core runtimes on Windows从 lib %USERPROFILE%\.nuget\packages\system.net.http.winhttphandler\4.4.0\lib\netstandard2.0 复制错误的程序集导致的结果而我们需要运行时汇编。

解决方法是将这些运行时程序集复制到 bin文件夹以使其由函数主机加载。之后Google.AdWords 24.1.0已安装,右键单击项目,Edit <FunctionProjectName>.csproj添加复制操作。有了 nuget 包的完整路径,我们不必先将程序集复制到我们的项目中。

请注意,一旦我们安装了新版本的软件包,这些路径可能会发生变化。

  <!-- For publish -->
  <ItemGroup>
    <None Include="$(USERPROFILE)\.nuget\packages\system.private.servicemodel\4.4.2\runtimes\win7\lib\netstandard2.0\System.Private.ServiceModel.dll">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
    <None Include="$(USERPROFILE)\.nuget\packages\system.net.http.winhttphandler\4.4.0\runtimes\win\lib\netstandard2.0\System.Net.Http.WinHttpHandler.dll">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
  </ItemGroup>
  <!-- For local debug -->
  <Target Name="CopyRuntime" BeforeTargets="Build">
    <Copy SourceFiles="$(USERPROFILE)\.nuget\packages\system.net.http.winhttphandler\4.4.0\runtimes\win\lib\netstandard2.0\System.Net.Http.WinHttpHandler.dll" DestinationFolder="$(OutputPath)\bin" />
    <Copy SourceFiles="$(USERPROFILE)\.nuget\packages\system.private.servicemodel\4.4.2\runtimes\win7\lib\netstandard2.0\System.Private.ServiceModel.dll" DestinationFolder="$(OutputPath)\bin" />
  </Target>

关于c# - 在 Azure Functions 上使用 AdWords API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50994295/

相关文章:

c# - Continue as First Statement in Concise If Else

java - Azure Java SDK - 无法获取资源指标 : ApiVersion: 2018-01-01 does not support query at non Arm resource Id level

c# - 按列排序的 Linq 查询摘要

C#:使用 "self"类型作为泛型参数?

c# - 在这种情况下我应该如何舍入 float ?

c# - 是否可以强制将所有 DateTime 属性建模为 DateTime2?

C# 异步,为什么我们需要 "hold"控制台来获取异步结果?

c# - 多次调用我的 WCF 服务方法

java - 如何向Azure管道控制台添加颜色?

azure - 我不小心从 Azure DevOps Wiki 中删除了一个页面。我怎样才能恢复它?