Azure Function fails to bind ILogger

RA. picture RA. · Jan 26, 2018 · Viewed 10.4k times · Source

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)

Answer

Mike S picture Mike S · Jan 26, 2018

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.