问题
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)
回答1:
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:
- See the nugget references used by the SDK
- Use those existing references and don't add the same dll with a different version.
回答2:
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.
回答3:
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 :-)
回答4:
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)
回答5:
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)
回答6:
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
回答7:
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
来源:https://stackoverflow.com/questions/48453482/azure-function-fails-to-bind-ilogger