如果不在C#实现(而不是CSX)中使用BlobAttribute,我就无法将blob类型的输入参数绑定到string/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)
不过,这是可行的(绑定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配置放在代码之外,这样我的函数就会变得更可移植。
发布于 2017-08-22 19:23:13
该问题被证明是与function.json
中支持新属性(configurationSource
)的最新运行时有关的
这将告诉运行时为函数配置使用config
(即function.json
)或C#属性。
本质上允许您像这样定义函数
现在,您可以将函数定义为
[FunctionName("Harvester")]
public static async Task Run(
[TimerTrigger]TimerInfo myTimer,
TraceWriter log,
TextReader configReader)
{
}
以及一个如下所示的function.json
{
"generatedBy": "Microsoft.NET.Sdk.Functions-1.0.0.0",
"configurationSource": "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"
}
],
"disabled": false,
"scriptFile": "...",
"entryPoint": "..."
}
或者像这样
[FunctionName("Harvester")]
public static async Task Run(
[TimerTrigger("0 */5 * * * *")]TimerInfo myTimer,
TraceWriter log,
[Blob("secured/app.config.json", FileAccess.Read)]TextReader configReader)
{
}
使用下面这样的更简单的配置
{
"generatedBy": "Microsoft.NET.Sdk.Functions-1.0.0.0",
"configurationSource": "attributes",
"bindings": [
{
"type": "timerTrigger",
"name": "myTimer"
},
],
"scriptFile": "...",
"entryPoint": "..."
}
请注意这两个示例中configurationSource
的值。
Visual Studio 2017的工具默认执行后者。如果您想要更改function.json以包含所有配置并更改configurationSource
,则需要在项目中包含该文件,并将其标记为始终复制。这个GIF展示了如何做到这一点。
https://stackoverflow.com/questions/45817579
复制相似问题