【发布时间】:2017-08-22 12:24:06
【问题描述】:
如果不使用 C# 实现(不是 CSX)中的 [BlobAttribute],我无法将 blob 类型的输入参数绑定到字符串/TextReader。
我得到的错误是:
Microsoft.Azure.WebJobs.Host: Error indexing method 'Functions.Harvester'.
Microsoft.Azure.WebJobs.Host: Cannot bind parameter 'configReader' to type
TextReader. 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.).
function.config:
"bindings": [
{
"type": "timerTrigger",
"schedule": "0 */5 * * * *",
"useMonitor": true,
"runOnStartup": false,
"direction": "in",
"name": "myTimer"
},
{
"type": "blob",
"name": "configReader",
"path": "secured/app.config.json",
"connection": "XXX",
"direction": "in"
}
],
函数签名(不绑定configReader):
[FunctionName("Harvester")]
public static async Task Run(
[TimerTrigger("0 */5 * * * *")]TimerInfo myTimer,
TraceWriter log,
TextReader configReader)
尽管如此 (BINDING configReader:
[FunctionName("Harvester")]
public static async Task Run(
[TimerTrigger("0 */5 * * * *")]TimerInfo myTimer,
TraceWriter log,
[Blob("secured/app.config.json", FileAccess.Read)]TextReader configReader)
关于如何在不指定 BlobAttribute 中的 blob 路径的情况下使其工作的任何想法。理想情况下,我会将 Blob 配置保留在代码之外,这样我的函数就会变得更加可移植。
【问题讨论】:
-
您在使用 VS 2017 工具吗?如果是,您能否在输出文件夹中检查一个名为
Harvester的文件夹,其中包含一个function.json文件。你能检查一下它是否有一个名为configurationSource的属性以及它的值吗? -
我正在使用 VS2017 工具,检查了文件,但没有名为
configurationSource的此类属性。你有没有提到configReader?如果是这样,那就像我原来的问题中描述的那样(顺便说一句,上面的清单来自 azure UI)。 -
不,
configurationSource是 2017 年工具引入的一个新属性,用于告诉函数运行时使用属性与配置文件。你能在你的csproj中检查``的版本吗?最新的是1.0.2,但请注意这应该将configurationSource设置为attributes,您需要将其更改为config以告诉运行时使用配置而不是属性。然后你需要在你的项目中包含那个 json 文件 -
你的问题是关于
Microsoft.NET.Sdk.Functions包,事实上我在1.0.0-alpha3。切换到1.0.2并渲染configurationSrouce。感谢那!如果我在项目中包含 JSON 文件,它是否需要指向我的输出文件夹中的位置 (bin\Debug...)?我已将它作为文件包含在我的源代码树中,但它仍会生成configurationSource: 'attributes' -
感谢分享,我可以确认它按预期工作。请升级您的评论作为答案,我会这样反馈。谢谢!
标签: c# azure azure-functions