azure-function-dependency-injection: Not working with netcoreapp2.1?
My function app is targeting netcoreapp2.1 - is it supposed to work with that?
I’m getting the error:
[29-Oct-18 14:09:22] Error indexing method 'WebhookProcessor.Run'
[29-Oct-18 14:09:22] Microsoft.Azure.WebJobs.Host: Error indexing method 'WebhookProcessor.Run'. Microsoft.Azure.WebJobs.Host: Cannot bind parameter 'cc1' to type ICC1. 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.).
My project file looks like this:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<AzureFunctionsVersion>V2</AzureFunctionsVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="3.0.1" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.23" />
<PackageReference Include="Willezone.Azure.WebJobs.Extensions.DependencyInjection" Version="1.0.1" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
</Project>
Startup class:
using MyApp.Functions;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Hosting;
using Microsoft.Azure.WebJobs.Logging;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System;
using Willezone.Azure.WebJobs.Extensions.DependencyInjection;
[assembly: WebJobsStartup(typeof(Startup))]
namespace MyApp.Functions
{
internal class Startup : IWebJobsStartup
{
public void Configure(IWebJobsBuilder builder) =>
builder.AddDependencyInjection<ServiceProviderBuilder>();
}
internal class ServiceProviderBuilder : IServiceProviderBuilder
{
private readonly ILoggerFactory _loggerFactory;
public ServiceProviderBuilder(ILoggerFactory loggerFactory) =>
_loggerFactory = loggerFactory;
public IServiceProvider Build()
{
var services = new ServiceCollection();
services.AddTransient<ICC1, CC1>();
return services.BuildServiceProvider();
}
}
public interface ICC1
{
int MyProperty { get; set; }
}
public class CC1 : ICC1
{
public CC1()
{
MyProperty = 42;
}
public int MyProperty { get; set; }
}
}
My function Run method:
[FunctionName("WebhookProcessor")]
public static async Task Run(
[QueueTrigger("webhooks")] CloudQueueMessage queueMessage,
[Table("webhooks")] CloudTable webhooksTable,
[Blob("webhooks", FileAccess.ReadWrite)] CloudBlobContainer webhooksContainer,
[Inject]ICC1 cc1,
ILogger logger)
{
}
I have copied Directory.Build.targets into the folder of my project file.
Any ideas?
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 1
- Comments: 22 (1 by maintainers)
Yep, changing my Azure Function project from targetting
netcoreapp2.1tonetstandard2.0resolved the “Make sure the parameter Type is supported by the binding.” error in the original post.No azure functions are supposed to target as follows netstandard2.0 AFAIK However even with that change I was struggling earlier today, basically DI works locally but upon upload to Azure I am continually getting a similar message to you;
I got it working by targeting
netstandard2.0.Problem is that it doesn’t register
Startupclass as extension when targetingnetcoreapp2.1: https://stackoverflow.com/q/53062309/2972I confirm that this works for me with target .net core 2.1 and current version of Microsoft.NET.SDK.Functions (1.0.26). Thanks @dantheman999301 .
Hi Did you find a solution for .net core 2.2? I have the same issue, startup is not called