我没有在不使用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"
}
],
功能签名(NOT BINDING 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配置保留在代码之外,这样我的功能就会变得更加便携。
答案 0 :(得分:6)
最近的问题是configurationSource
function.json
)的最新运行时问题
这告诉运行时使用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显示了如何做到这一点。