【问题标题】:Azure functions that are timer based complain about log type基于计时器的 Azure 函数抱怨日志类型
【发布时间】:2018-10-28 16:20:06
【问题描述】:

我遇到了与this question完全相同的问题

但是没有一个答案有效,谷歌搜索了很长时间,我的版本已经更新等等,但我仍然得到同样的错误

代码是示例模板

using System;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;

namespace NWMPosNGPimFeeder
{
    public static class Function1
    {
        [FunctionName("Function1")]
        public static void Run([TimerTrigger("0 */1 * * * *")]TimerInfo myTimer, TraceWriter log)
        {
            log.Info($"C# Timer trigger function executed at: {DateTime.Now}");
        }
    }
}

主机等版本如下,包括实际错误

[21/5/2018 2:03:29 AM] Host has been specialized
Listening on http://localhost:7071/
Hit CTRL-C to exit...
[21/5/2018 2:03:29 AM] Reading host configuration file 'C:\Users\MattDouhan\source\repos\NWMPosNGPimFeeder\NWMPosNGPimFeeder\bin\Debug\net461\host.json'
[21/5/2018 2:03:29 AM] Host configuration file read:
[21/5/2018 2:03:29 AM] {
[21/5/2018 2:03:29 AM] }
[21/5/2018 2:03:30 AM] Loaded custom extension 'BotFrameworkConfiguration'
[21/5/2018 2:03:30 AM] Loaded custom extension 'SendGridConfiguration'
[21/5/2018 2:03:30 AM] Loaded custom extension 'EventGridExtensionConfig'
[21/5/2018 2:03:31 AM] Generating 1 job function(s)
[21/5/2018 2:03:31 AM] Starting Host (HostId=desktop7cks1do-1972353084, Version=1.0.11232.0, ProcessId=2668, Debug=False, Attempt=0)
[21/5/2018 2:03:31 AM] A ScriptHost error has occurred
[21/5/2018 2:03:31 AM] Microsoft.Azure.WebJobs.Host: Error indexing method 'Function1.Run'. Microsoft.Azure.WebJobs.Host: Cannot bind parameter 'log' to type TraceWriter. Make sure the parameter Type is supported by the binding. If you're using binding extensions (e.g. ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. config.UseServiceBus(), config.UseTimers(), etc.).
[21/5/2018 2:03:31 AM] Error indexing method 'Function1.Run'

【问题讨论】:

  • 您能否提供一些信息,例如您的函数应用版本(v1 或 v2)、cli、主机版本。见例子>i.stack.imgur.com/OuOFu.png
  • 添加到问题

标签: azure azure-functions


【解决方案1】:

问题在于 cli VS 使用的旧函数。

版本=1.0.11232.0

表示cli版本为1.0.4。这个旧版本确实会导致您的问题,但它已经在新版本中得到修复。

检查您的Azure Functions and Web Jobs Tools 版本。

最新扩展 15.0.40502.0,如果 VS 无法下载新版本的 cli,将使 VS 使用 cli 1.0.4。此下载过程在后台进行,似乎没有明确的警告。见This GitHub issue

解决方案

我建议你删除C:\Users\UserName\AppData\Local\AzureFunctionsTools文件夹并重新启动你的VS重新下载。

当我们创建一个函数应用时,我们可以在对话框中看到Making sure all templates are up to date...的提示

稍等片刻,我们可以看到提示变化为

如果3m后没有变化(你这边下载200M文件的时间),检查C:\Users\UserName\AppData\Local\AzureFunctionsTools\Releases\1.0.12.1文件夹看是否为空。如果为空,则表示无法通过 VS 进行下载。我们必须手动完成。

您可以在C:\Users\UserName\AppData\Local\AzureFunctionsTools\feed.json找到cli、itemTemplates和projectTemplates的下载链接。

您可以参考1.0.10文件夹构建类似的文件夹结构。

【讨论】:

  • 我有点困惑抱歉,我有 Microsoft.net.sdk.functions 1.0.13 你是说另一个 nuget 包吗? O 不确定如何检查您所指的内容
  • @MattDouhan 你的意思是不确定如何检查Azure Functions and Web Jobs Tools 版本?
  • 是的,但没关系,我删除了文件夹并重新启动,下载新版本后它运行良好:)
猜你喜欢
  • 2019-10-22
  • 2015-07-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-22
  • 2021-12-22
  • 2021-05-10
  • 1970-01-01
相关资源
最近更新 更多