I'm not able to bind an input parameter of type blob to either string/TextReader without using the [BlobAttribute] in a C# implementation (not CSX).
The error I'm getting is:
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"
}
],
Function signature (NOT BINDING configReader
):
[FunctionName("Harvester")]
public static async Task Run(
[TimerTrigger("0 */5 * * * *")]TimerInfo myTimer,
TraceWriter log,
TextReader configReader)
This would work though (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)
Any idea on how to get it working without specifying the blob path in BlobAttribute
. I'd ideally keep the Blob config outside of the code, that way my function would become more portable.
The issue turned out to be with the latest runtime supporting a new property (
configurationSource
) infunction.json
This tells the runtime to use either
config
(which isfunction.json
) or C# attributes for function config.essentially allowing you to either define your function like this
Now you can either define your function as
along with a
function.json
that looks like thisor like this
with a simpler config like this
note the value of
configurationSource
in both examples.The tooling for Visual Studio 2017 does the latter by default. If you wanna change your function.json to include all your config and change the
configurationSource
you will need to include the file in your project and mark it as always copy. This GIF shows how to do that.