【问题标题】:Cannot bind function parameter to type TraceWriter after publishing to Azure发布到 Azure 后无法将函数参数绑定到类型 TraceWriter
【发布时间】:2017-12-12 03:32:48
【问题描述】:

我正在关注https://mikhail.io/2017/12/precompiled-azure-functions-in-fsharp/的指南:

  1. 已创建 dotnet f# 项目:dotnet new classlib --language F# --name HelloFunctions
  2. 添加了对函数的引用:dotnet add package Microsoft.NET.Sdk.Functions
  3. 添加了如下文件 Library.fs 中所述的新功能,添加了配置文件等。
  4. 编译函数
  5. dotnet build && dotnet publish && cd bin/Debug/netstandard2.0/publish && func start在本地成功启动。
  6. 将其发布到 Azure:func azure functionapp publish <name>
  7. Azure看功能,没问题。
  8. 当我通过单击树中的名称导航到功能时,会弹出错误消息:

    Function ($Hello) Error: Microsoft.Azure.WebJobs.Host:
    Error indexing method 'Functions.Hello'. 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.).
    
  9. 该功能似乎不起作用。可能是因为上面的错误。

库.fs

namespace HelloFunctions

open System
open Microsoft.Azure.WebJobs
open Microsoft.Azure.WebJobs.Host

module Say =
let private daysUntil (d: DateTime) =
    (d - DateTime.Now).TotalDays |> int

let hello (timer: TimerInfo, log: TraceWriter) =
    let christmas = new DateTime(2017, 12, 25)

    daysUntil christmas
    |> sprintf "%d days until Christmas"
    |> log.Info

【问题讨论】:

  • 库版本不兼容:您的程序集是针对与函数框架使用的不同的 .NET 版本编译的。

标签: azure f# azure-functions


【解决方案1】:

听起来很像程序集版本冲突(运行时运行Microsoft.Azure.WebJobs.Host.dll 的一个版本,而您的应用程序引用了另一个)。

我的猜测是您使用运行时版本 2.0 编译了本地应用程序,而 Azure Function App 配置为 1.0(默认)。请检查。

【讨论】:

    猜你喜欢
    • 2018-06-16
    • 2018-09-15
    • 2021-12-30
    • 2019-07-13
    • 2020-04-05
    • 2021-08-16
    • 2021-12-31
    • 2015-02-22
    • 1970-01-01
    相关资源
    最近更新 更多