Azure / Azure-Functions

1.11k stars 197 forks source link

Adding a package that references Microsoft.Extensions.Logging.Abstractions breaks function #334

Open brettsam opened 7 years ago

brettsam commented 7 years ago

From @dersia at #293:

Hi there I just realized, that there seems to be an issue with the new ILogger. If I select the ILogger, everything works as expected and there is no issue at all, but if I consume a nuget-package which has dependency on Microsoft.Extensions.Logging.Abstractions it stops working. I actually get a failure upon loading the function:

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

dersia commented 7 years ago

@brettsam I just created a sample:

https://github.com/dersia/FuntionsLoggingTest

the TestPackage Folder contains the nuget-package and the Functions folder contains the functions files

dersia commented 7 years ago

@brettsam are there any news on this one? can I help you investigating?

samontgo commented 7 years ago

You may be able to move forward if you change the version to 1.1.0.

<ItemGroup>
    <PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="1.1.0" />
</ItemGroup>

Perhaps it depends on the version that the Functions apps have built into them?

lindydonna commented 7 years ago

@brettsam Any reason why this issue is in this repo, rather than script or SDK?

julKali commented 6 years ago

A year later, I'm having the same issue as op. Any suggestions?

marxxxx commented 6 years ago

same here

mnty commented 6 years ago

Which version of the Microsoft.Extensions.Logging.Abstractions package do you have installed?

marxxxx commented 6 years ago

@mnty: in my case it was 1.1.2

julKali commented 6 years ago

My problem in detail is that I have a project on which pretty much all other project depend on, including the Startup Functions project. Now this first one needs the latest version of Microsoft.Extensions.Logging.Abstractions to use WebApi's Client package. Thus, in order to make my Functions project depend on the first project, it has to have the latest Abstractions, too.

brettsam commented 6 years ago

The version of this package the Functions host uses in 1.1.1, so that version should be guaranteed to work.

@fabiocav -- is there any way to move this forward with direct references to a newer version?

It is related to our binding redirect issue. For more information on that, see https://github.com/Azure/azure-functions-host/issues/992.

joseclament commented 6 years ago

Hi, I am using the Azure function(function app, custom code) with “FUNCTIONS_EXTENSION_VERSION=beta” and target framework “netstandard2.0”. I published the function on the azure and getting the following exception "Microsoft.Extensions.Logging.Abstractions, Version=2.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified. Could not load the specified file". I’ve checked and these files are in my bin folder. I was able to perform the local debug and integration tests.But no idea why it’s failing on the server. Believe the function load all the assemblies from my application bin folder and honour the version on the bin folder. Not from any cli context.

Any help much appreciated as I am really stuck on this.

larry-lau commented 6 years ago

I have the same issue on beta and the Function blade show a error dialog with the following message.

The function runtime is unable to start. System.Private.CoreLib: Could not load file or assembly 'Microsoft.Extensions.Logging.Abstractions, Version=2.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified. System.Private.CoreLib: Could not load the specified file.

I fixed my function by using Microsoft.Extensions.Logging.Abstractions (2.0.0) in my other projects since Microsoft.Azure.WebJobs (3.0.0-beta5) is using this version.

joseclament commented 6 years ago

I have many libraries that is using "Microsoft.Extensions.Logging.Abstractions, Version=2.1.0.0" and those libraries are consumed by many other solutions. So it's not an easy option for me to down grade the dll version. More over we are developing all our projects using the .NET core 2.1. I've updated all the dependencies to target .NET core 2.1, still no joy :(

brettsam commented 6 years ago

@larry-lau, @joseclament -- Are you targeting functions v1 or v2?

pmiddleton commented 6 years ago

I'm getting this same error.

I'm targeting functions v1 on full framework 4.7.1 and version 2.1 of Microsoft.Extensions.Logging. This is a new project I just created this morning.

larry-lau commented 6 years ago

@brettsam I am targeting functions v2.

joseclament commented 6 years ago

@brettsam trageting functions V2.

joseclament commented 6 years ago

@brettsam , I have a function project and a web api project in the same solution, and both are calling my second project which was handling all the business logics, including Db calls. The web api part is working without any issue and only the function part is throwing the exception. Believe the azure function will load all the dlls from the bin folder while executing it and not anything from its own context. If so it may have different version of the dlls in the bin and context. I've found these issue while debugging locally while some of the dlls minor versions were different from the cli versions, so I have to manually copy my bin dlls to the cli and its started working. Please let me know how the run time on azure function will handle dlls.

chadgruka commented 6 years ago

Seeing the same issue related to Microsoft.Extensions.Configuration namespace. It feels like it's inheriting all the DLLs used by the SDK, rather than isolating the DLLs in the bin folder of the Azure Function. Can this be prevented, or is this expected?

WillEastbury commented 5 years ago

I've seen this today too with this package Microsoft.AspNetCore.Authentication.JwtBearer (2.2.0) on Functions V2 (host 2.0.12175.0), and rolling that package back as it has a dependency on the abstractions lib seems to have fixed my issue.

For anyone currently still struggling with this :-

  1. Add this to your function app's csproj file.

  2. Then run the app and look for this error during package restore :-

error NU1605: Detected package downgrade: Microsoft.Extensions.Logging.Abstractions from 2.2.0 to 2.1.0. Reference the package directly from the project to select a different version.

The following line after that error will tell you which package is the problem.

In my case I needed to downgrade my JwtBearer package to 2.1 as that had the dependency that was breaking everything.

<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="2.1.0" />

Another error that seems to potentially occur with this downgrade issue at runtime is this one.

"System.Private.CoreLib: Exception while executing function: Microsoft.Azure.WebJobs.Host: Exception binding parameter 'req'. System.Private.CoreLib: Cannot create an abstract class." - that said, most people won't see that (and I only did as I tried to work around this by changing my iLogger to a TraceWriter instance a'la V1) then it started to fail with this error - downgrading the package fixed both issues.

manuel-guilbault commented 5 years ago

I've debugged using SourceLink, and the issue seems to be that the ILogger type used by my Azure function assembly isn't the same ILogger type instance used by the Azure functions host, as this equality evaluates to true.

ColbyTresness commented 5 years ago

@brettsam is this still relevant?

kvinther commented 5 years ago

I encountered the exact same issue today. For me it was simply, as also hinted above, that some of my referenced projects had the NuGet package for a newer version of Microsoft.Extensions.Logging.Abstractions installed.

ganesh-gawande commented 3 years ago

I am facing same issue - here are more details - I have Azure function and one class library. Azure function has reference to Microsoft.Extensions.Logging.Abstraction 5.0.0 via - Microsoft.Azure.Functions.Extension package

Now I want to use logging in class library as well. So I have added nuget package Microsoft.Extensions.Logging.Abstraction 5.0.0 to my class library.

Now after this when I run the azure function - I am getting following error - Microsoft.Azure.WebJobs.Extensions.DurableTask: Value cannot be null. (Parameter 'loggerFactory'). Value cannot be null. (Parameter 'provider')

If I remove the reference from class library - then Azure functions works fine.

Can someone help me in this.?