27

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)

Janusz Nowak
  • 2,078
  • 1
  • 13
  • 29
RA.
  • 1,329
  • 1
  • 10
  • 15

10 Answers10

31

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.
Mike S
  • 2,719
  • 1
  • 19
  • 12
  • 4
    Thanks. The problem was that I was trying to use Logging.Abstractions v2.0.0.0 while the SDK is using 1.1.1 – RA. Feb 02 '18 at 01:11
  • I believe the just released version 1.0.19 of Microsoft.NET.Sdk.Functions is using v2.1.0 of Microsoft.Extensions.Logging.Abstractions. – Jan Aagaard Sep 03 '18 at 08:24
  • 1
    This is the right answer, and is what was causing the same error for me. More specifically, I had this error b/c my Azure function project (v2 .Net core) was referencing my own projects that had dependencies on Microsoft.Extensions.Logging v2.2.0 NuGet package, which resulted in the AF project's Microsoft.NET.Sdk.Functions Nuget package upgrading its Microsoft.Extensions.Logging related packages (several of them) from the default v2.2.1 to v2.2.0. Hope this helps. – Chuck Dec 04 '18 at 20:39
  • 2
    In my case, I needed to downgrade `Microsoft.Extensions.Logging.Abstractions` from `3.1.0` to `2.2.0` – thmshd Dec 19 '19 at 07:32
  • If I use `Microsoft.Extensions.Logging` `5.0.0` in another assembly that the Azure function depends on I run into the OP's issue. However, if I downgrade to `3.1.12` in the other assembly then everything works great. Fairly opaque. Lost a fair amount of time because of this issue. – user3613932 Feb 23 '21 at 07:25
11

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.

Batu
  • 431
  • 1
  • 6
  • 17
  • Was referencing a project that uses EF 2.2 and removing the reference took care of the error in the Function. – Wavel Dec 17 '18 at 23:06
  • This was a huge time saver for me. Thanks for posting! – Steve Scheffler Dec 29 '18 at 23:39
  • I can verify that still still works with an Azure Function v3 project, which I believe uses .NETCore 3.1. I downgraded my EF packages to 2.2.0 and it works without error. – K. Akins Feb 24 '20 at 02:28
4

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 :-)

infl3x
  • 1,312
  • 17
  • 23
3

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)

toralux
  • 520
  • 4
  • 6
3

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.

pkucas
  • 89
  • 5
1

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

Neil
  • 3,994
  • 3
  • 34
  • 36
0

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

SimonF
  • 1
0

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

Ondrej Rozinek
  • 429
  • 4
  • 11
0

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

gpkarnik
  • 1
  • 1
0

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.

chris
  • 1