azure-function-dependency-injection icon indicating copy to clipboard operation
azure-function-dependency-injection copied to clipboard

Binding fails with target frameworks netcoreapp 2.1 and 2.2

Open SpicySyntax opened this issue 6 years ago • 10 comments

This package works fine when I target netcoreapp2.0. But when I target anything above that I get Microsoft.Azure.WebJobs.Host: Error indexing method 'UploadImage'. Microsoft.Azure.WebJobs.Host: Cannot bind parameter 'cosmosDbClient' to type ICosmosDbClient. Make sure the parameter Type is supported by the binding. If you're using binding extensions (e.g. Azure Storage, ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.).

SpicySyntax avatar Apr 05 '19 19:04 SpicySyntax

I have exactly the same issue

Extentsoftware avatar Apr 15 '19 13:04 Extentsoftware

check if the package you deploy have non-empty extensions.json file. If not, update functions sdk to 1.0.26.

miqm avatar Apr 20 '19 13:04 miqm

I tried this but still no extensions.json, and it still failed like before. See this gist for some example code

Do I need to create my own extensions.json that references the DI extension?

SpicySyntax avatar Apr 25 '19 17:04 SpicySyntax

no, the extensions.json should be created automatically by sdk. please share also the csproj file. You can also check my project for reference: https://github.com/miqm/playground

miqm avatar Apr 25 '19 18:04 miqm

@miqm Thanks for the example I will look at it, I updated the gist with my csproj

SpicySyntax avatar Apr 25 '19 19:04 SpicySyntax

Looks like you're using 1.0.24 - you should be on sdk 1.0.26 - have you tried upgrading? I know it doesn't work under 1.0.26

Extentsoftware avatar Apr 25 '19 19:04 Extentsoftware

I duplicated your setup in the example, and the startup code runs fine but the binding to the [Inject] attribute still failes with 'Microsoft.Extensions.DependencyInjection.Abstractions: Unable to resolve service for type 'ObjectDetection.Services.ICosmosDbClient' while attempting to activate 'ObjectDetection.UploadImage'.' Hmmm, any idea here?

SpicySyntax avatar Apr 25 '19 20:04 SpicySyntax

Share your code if possible.

miqm avatar Apr 26 '19 21:04 miqm

Share your code if possible.

@miqm Here is an upated Gist with the relevant source code. Thanks

SpicySyntax avatar Apr 30 '19 14:04 SpicySyntax

Not sure if this is will work, but try separate code with extensions into a library that function app will depend upon.

miqm avatar May 08 '19 07:05 miqm