Azure / azure-functions-dotnet-worker

Azure Functions out-of-process .NET language worker
MIT License
431 stars 184 forks source link

Cannot use multiple attributes per parameter #2739

Closed vanillajonathan closed 1 month ago

vanillajonathan commented 1 month ago

Description

I cannot bind a parameter such as client with both the BlobTrigger and the BlobInput attributes.

Worker failed to index functions
 Result: Failure
Exception: System.ArgumentException: Key already exists in map (Parameter 'key')
    at Google.Protobuf.Collections.MapField`2.Add(TKey key, TValue value)
    at Microsoft.Azure.Functions.Worker.Grpc.FunctionMetadata.FunctionMetadataRpcExtensions.GetBindingInfoList(IFunctionMetadata funcMetadata) in D:\a\_work\1\s\src\DotNetWorker.Grpc\FunctionMetadata\FunctionMetadataRpcExtensions.cs:line 34
    at Microsoft.Azure.Functions.Worker.GrpcWorker.GetFunctionMetadataAsync(String functionAppDirectory) in D:\a\_work\1\s\src\DotNetWorker.Grpc\GrpcWorker.cs:line 185
Stack:    at Google.Protobuf.Collections.MapField`2.Add(TKey key, TValue value)
    at Microsoft.Azure.Functions.Worker.Grpc.FunctionMetadata.FunctionMetadataRpcExtensions.GetBindingInfoList(IFunctionMetadata funcMetadata) in D:\a\_work\1\s\src\DotNetWorker.Grpc\FunctionMetadata\FunctionMetadataRpcExtensions.cs:line 34
    at Microsoft.Azure.Functions.Worker.GrpcWorker.GetFunctionMetadataAsync(String functionAppDirectory) in D:\a\_work\1\s\src\DotNetWorker.Grpc\GrpcWorker.cs:line 185.

Steps to reproduce

[Function(nameof(Function1))]
[BlobOutput("import/processed/{name}")]
public async Task Run([BlobTrigger("import/{name}"), BlobInput("import/{name}")] BlobClient client, string name)
{
}
matt-lethargic commented 1 month ago

I'm hitting the same problem, seems to be contrary to the documentation. Looking at the error it seems to be trying to convert to JSON?!

Not working

[Function(nameof(DeliveryFunction))]
[BlobOutput("processed/{name}", Connection = "Storage")]
public async Task<byte[]> Run([BlobTrigger("reporting/{name}", Connection = "Storage")] Stream inputStream, string name)
{ }

Error

Error converting 1 input parameters for Function 'DeliveryFunction': Cannot convert input parameter 'inputStream' to type 'System.IO.Stream' from type 'System.ReadOnlyMemory`1[[System.Byte, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]'.
Error:System.Text.Json.JsonException: '-' is invalid within a number, immediately after a sign character ('+' or '-'). Expected a digit ('0'-'9'). Path: $ | LineNumber: 0 | BytePositionInLine: 1.

If I take off the [BlobOutput] attribute then it works

[Function(nameof(DeliveryFunction))]
public async Task Run([BlobTrigger("reporting/{name}", Connection = "Storage")] Stream inputStream, string name)
{ }
satvu commented 1 month ago

@vanillajonathan Could you refactor your function to look more like this example? Input bindings shouldn't be combined for one parameter (best practice is to have one binding -> one parameter).

@matt-lethargic I think you are facing a a different issue described here: https://github.com/Azure/azure-functions-dotnet-worker/issues/1969

satvu commented 1 month ago

Closing as answered - @matt-lethargic if the linked issue and explanation does not help solve your problem, please open up a new issue to track. Thanks!

vanillajonathan commented 1 month ago

@satvu Yes, I can refactor my function to look more like that example but I think Azure function should either be able to handle multiple attributes on a parameter or it should throw a exception with a friendly error message.