29
votes

My function is referencing an assembly that references Microsoft.Extensions.Logging.Abstractions 2.0.0. If I add a nuget reference to that version to the function's assembly, function execution fails with:

[1/25/2018 11:14:46 PM] Microsoft.Azure.WebJobs.Host: Error indexing method 'TrainingFunction.Run'. Microsoft.Azure.WebJobs.Host: Cannot bind parameter 'log' to type ILogger. 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.).

Is it possible to use the newer logger in Azure functions ? (SDK 1.0.7)

10

10 Answers

31
votes

What is probably happening is that the SDK is binding to version X of the ILogger assembly and your user code is binding to version Y. The binding engine then doesn't recognize your parameter's type as being the same since they're from different assemblies. (this can happen with any other type too).

Generally the fix is to:

  1. See the nugget references used by the SDK
  2. Use those existing references and don't add the same dll with a different version.
11
votes

I was somehow also having the same error, but it was the package version for Microsoft.EntityFrameworkCore.SqlServer what is causing the issue.

Downgrading Microsoft.EntityFrameworkCore.SqlServer v2.2.0 to v2.1.4 did the trick.

I assume that there is a version mismatch between logging.abstractions libraries for this package.

4
votes

For me, the problem was that I needed to explicitly declare the Azure Functions Version in my .csproj file.

I added <AzureFunctionsVersion>v2</AzureFunctionsVersion> after the <TargetFramework> element:

<PropertyGroup>
   <TargetFramework>netstandard2.0</TargetFramework>
   <AzureFunctionsVersion>v2</AzureFunctionsVersion>
</PropertyGroup>

Hope that helps someone :-)

3
votes

Also binding-order could cause this failure.

Changing from parameter order ...

     [FunctionName("SomeFunction")]
     public static async Task Run([BlobTrigger("path", Connection = "conn")]
        ILogger logger, ExecutionContext context, Stream stream, string name) {}

... to ...

     [FunctionName("SomeFunction")]
     public static async Task Run([BlobTrigger("path", Connection = "conn")]
        Stream stream, string name, ILogger logger, ExecutionContext context) {}

... fixed my problem. (Microsoft.NET.Sdk.Functions v1.0.24)

3
votes

For me, I was using NuGet package Microsoft.Extensions.Logging on a project referenced by my Azure function. Uninstalled this package and my error (this exact error) went away. I didn't actually need the NuGet package to use ILogger in my Azure function.

 [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
            ILogger log)

Edit: Also downgrading to Microsoft.Extensions.Http 2.1.0 worked on another occurrence of this error. If you still need the Extensions package (for IHttpClientFactory for example) it's possible to get this logging error because of an SDK version conflict with 3.1.1.

1
votes

As stated by one of MS employees the cause could be:

we don't quite yet support .NET Core 2.2, but we have the work underway and should ship in January.

https://github.com/Azure/azure-functions-host/issues/3854#issuecomment-449034719

0
votes

Another reason for the same error...

Somehow I ended up with a using statement referencing Microsoft.Build.Framework which has its own version of ILogger the fix is just to replace this with Microsoft.Extensions.Logging which the functions app is expecting

0
votes

This will also happen when updating Azure Functions/Durable Functions from v2 to v3. You need to manually edit .csproj to resolve the ILogger reference problem.

<PropertyGroup>
  <TargetFramework>netcoreapp3.1</TargetFramework>
  <AzureFunctionsVersion>v3</AzureFunctionsVersion>   
</PropertyGroup>
<ItemGroup>
    ...
   <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.2" />
</ItemGroup>

The function will continue to report a run-time module error. Then you have to try to create new Azure Function v3 project in Visual Studio to download the templates for run-time modules. More information on the procedure is provided in the official documentation: Azure Functions runtime versions overview

0
votes

I had to uninstall Microsoft.Extensions.Logging nuget package from the solution.

0
votes

I suddenly started getting the ILogger binding error after auto-updating my Nuget packages.

I couldn't find any explict references to ILogger extensions in my solution files. It turned out the culprit was a different extension Microsoft.Extensions.Caching.Memory that updated to v5.00 (.NET 5?). Downgrading that package to the prior version 3.1.15 fixed the error (I was originally at v3.1.4). I wonder if any v5.x extension package would trigger this issue.