Azure / azure-functions-dotnet-extensions

Azure Functions .NET extensions
MIT License
75 stars 42 forks source link

Method not foundMicrosoft.Azure.Functions.Extensions.DependencyInjection.IFunctionsHostBuilder.get_Services() since .Net Core 3.1 release #32

Closed FrankGagnon closed 4 years ago

FrankGagnon commented 4 years ago

Hi,

When updating our nuget packages like Microsoft.Extensions.DependencyInjection.Abstractions and Microsoft.Extensions.Configuration to version 3.1.0 released with .Net Core 3.1 yesterday, the Function host fails to start with the following error : Method not found: 'Microsoft.Extensions.DependencyInjection.IServiceCollection Microsoft.Azure.Functions.Extensions.DependencyInjection.IFunctionsHostBuilder.get_Services()'

I'm using the latest VS version, 16.4.0 and the v3 preview function runtime.

Thanks, Frank

hiiru commented 4 years ago

I also have this issue with .NET Core 3.1 and Microsoft.Extensions.* 3.1.0 packages. It only occurs if [assembly: FunctionsStartup(typeof(Startup))] is set (or [assembly: WebJobsStartup(typeof(Startup))] when using the WebJobs SDK to configure DI).

I think it's a similar issue as https://github.com/Azure/azure-functions-dotnet-extensions/issues/29 back with .NET Core 3.0.

My current workaround is using Microsoft.Extensions.* packages in version 3.0.0.

eliashdezr commented 4 years ago

I'm getting a similar error while trying to do a GET on a HttpTrigger function:

Microsoft.Extensions.DependencyInjection.Abstractions: Unable to resolve service for type

This is my current setup:

And this is my .csproj

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <AzureFunctionsVersion>v3</AzureFunctionsVersion>
    <LangVersion>latest</LangVersion>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.0.0" />
    <PackageReference Include="Microsoft.Extensions.Http" Version="3.1.0" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.1" />
    <PackageReference Include="Utf8Json" Version="1.3.7" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
</Project>

Startup.cs file:

using Microsoft.Azure.Functions.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;
using Demo.Domain.Interfaces.Repository;

namespace Demo.Functions
{
    public class Startup : FunctionsStartup
    {
        public override void Configure(IFunctionsHostBuilder builder)
        {
            builder.Services.AddSingleton<IDemoRepo, DemoRepo>();
        }
    }
}

local.settings.json

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet",
    "FUNCTIONS_EXTENSION_VERSION": "~3"
  }
}

host.json

{
  "version": "2.0",
  "healthMonitor": {
    "enabled": true,
    "healthCheckInterval": "00:00:10",
    "healthCheckWindow": "00:02:00",
    "healthCheckThreshold": 6,
    "counterThreshold": 0.80
  },
  "functionTimeout": "00:10:00"
}

This might be related https://github.com/Azure/azure-functions-dotnet-extensions/issues/5

IGx89 commented 4 years ago

Also just ran into this issue upgrading a working function app from v3-preview/ASP.NET Core 3.0 to v3/ASP.NET Core 3.1. Guess we're not upgrading to 3.1 yet!

IGx89 commented 4 years ago

FYI I fixed my issue updating azure-functions-core-tools from 3.0.1740 to 3.0.1975. It just came out two days ago, so none of you above would have had it yet.

eliashdezr commented 4 years ago

FYI I fixed my issue updating azure-functions-core-tools from 3.0.1740 to 3.0.1975. It just came out two days ago, so none of you above would have had it yet.

Same error, with azure-functions-core-tools@3.0.1975 issue doesn't go away.

StefanSchoof commented 4 years ago

Updating to 3.0.1975 solved this for me also. But only if I start the function from command line. Starting in Visual Studio the error still occurs. I think VS has an older version of the runtime , which still is on dotnet core 3.0, bundled.

eliashdezr commented 4 years ago

Updating to 3.0.1975 solved this for me also. But only if I start the function from command line. Starting in Visual Studio the error still occurs. I think VS has an older version of the runtime , which still is on dotnet core 3.0, bundled.

That resolved my issue too.

fabiocav commented 4 years ago

@FrankGagnon can you validate with the latest version and let us know if this is still an issue?

ghost commented 4 years ago

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.

laurentlbm-rc commented 4 years ago

I am not getting this error when developing, but I am when the function is published to Azure:

The function runtime is unable to start. AzureFunctions.Test: Method not found: 'Microsoft.Extensions.DependencyInjection.IServiceCollection Microsoft.Azure.Functions.Extensions.DependencyInjection.IFunctionsHostBuilder.get_Services()'.

Session Id: 05fd31eb4d364d95b0ae80d281dbc38d

Timestamp: 2020-01-14T16:30:42.146Z

Here is my .csproj:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <AzureFunctionsVersion>v3</AzureFunctionsVersion>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <DefineConstants>DEBUG;TRACE</DefineConstants>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.0.0" />
    <PackageReference Include="Microsoft.Extensions.Configuration.AzureKeyVault" Version="3.1.0" />
    <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.0" />
    <PackageReference Include="Microsoft.Extensions.Options" Version="3.1.0" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.2" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
</Project>
fabiocav commented 4 years ago

@laurentlbm-rc is your Function App version on Azure set to 3.0? (~3)?

Can you please share an invocation ID, region and timeframe so we can look at some details?

laurentlbm-rc commented 4 years ago

@fabiocav Ah, I feel stupid, that was the issue, it's working fine now. I'm not the one who created the function app and I didn't think to look at that.

robertracz commented 4 years ago

I am having the same issue in production:

Error: The function runtime is unable to start. DsInternal.Functions: Method not found: >'Microsoft.Extensions.DependencyInjection.IServiceCollection Microsoft.Azure.Functions.Extensions.DependencyInjection.IFunctionsHostBuilder.get_Services()'. Session Id: 393e6f10d28544d9ab1e49f44286e178 Timestamp: 2020-01-14T23:14:26.600Z

Everything is fine locally, however in the function app i am getting the same exception on startup. My Function App is referencing two netstandard2.1 libraries which might has to do something with it... FUNCTIONS_EXTENSION_VERSION is set ti ~3.

Function app:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <AzureFunctionsVersion>V3</AzureFunctionsVersion>
    <LangVersion>8.0</LangVersion>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.0.0" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.2" />
    <PackageReference Include="WindowsAzure.Storage" Version="9.3.3" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="3.0.10" />
    <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
  </ItemGroup>
  .
  . 
  .
</Project>

class libraries:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netstandard2.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.7" />
    <PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="3.1.0" />
    <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.0" />
    <PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="3.1.0" />
    <PackageReference Include="Microsoft.Extensions.Http" Version="3.1.0" />
    <PackageReference Include="Microsoft.Extensions.Options" Version="3.1.0" />
    <PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="3.1.0" />
    <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
  </ItemGroup>
</Project>
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netstandard2.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="AutoMapper" Version="9.0.0" />
    <PackageReference Include="CsvHelper" Version="12.2.2" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.0">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.0">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
  </ItemGroup>
</Project>

Wondering if EF Core reference is the issue although it should not be? I had issues before locally but not since upgrading to dotnet core 3.1.

Regards,

Robert

itorian commented 4 years ago

Same issue when upgraded from netcoreapp3.0 to netcoreapp3, when i run it locally i get below error:

Method not found: 'Microsoft.Extensions.DependencyInjection.IServiceCollection Microsoft.Azure.Functions.Extensions.DependencyInjection.IFunctionsHostBuilder.get_Services()'.
Value cannot be null. (Parameter 'provider')

I've following packages and settings in place

<PropertyGroup>
  <TargetFramework>netcoreapp3.1</TargetFramework>
  <AzureFunctionsVersion>v3</AzureFunctionsVersion>
</PropertyGroup>
<ItemGroup>
  <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.2" />
  <PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.0.0" />
  <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.1" />
  <PackageReference Include="AWSSDK.SimpleNotificationService" Version="3.3.101.111" />
</ItemGroup>

Then I create a brand new project and moved all my *.cs files one by one and i was able to run it locally. So I have no idea, why above error appeared, during troubleshooting I cleared all bin and obj, and couple of other things and no success.

Once I had this working in brand new project, then I tried to publish function app on azure. I'm using Visual Studio 16.4.3 publish wizard 'Azure App Service Plan Linux' option, then clicked on 'Select Existing' radio. Then I was prompted to select my existing function app, at the end clicked on 'Publish'.

I received publish success message:

2>Publishing C:\Users\abhimanyu\source\repos\app1-tfs\App1.Function.Core.New\obj\Release\netcoreapp3.1\PubTmp\App1.Function.Core.New - 20200116184741772.zip to https://xxxxfunctionpoc1.scm.azurewebsites.net/api/zipdeploy...
========== Build: 1 succeeded, 0 failed, 5 up-to-date, 0 skipped ==========
========== Publish: 1 succeeded, 0 failed, 0 skipped ==========

When I opened this on azure portal, there is no function item, however everything worked well locally. image

FUNCTIONS_EXTENSION_VERSION is set to ~3 | Location: Central US

ghost commented 4 years ago

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.

kevinbrydon commented 4 years ago

For anyone still having issues. What worked for me was changing the AzureFunctions entry in my projct file from v2 to v3

My project file now looks like this

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <TargetFramework>netcoreapp3.1</TargetFramework>
        <AzureFunctionsVersion>v3</AzureFunctionsVersion>
    </PropertyGroup>
    <ItemGroup>
        <PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.0.0" />
        <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.EventGrid" Version="2.1.0" />
        <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.2" />
    </ItemGroup>
    <ItemGroup>
      <ProjectReference Include="..\My.Namespace\My.Namespace.csproj" />
        ...
    </ItemGroup>
    <ItemGroup>
        <None Update="host.json">
            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        </None>
        <None Update="local.settings.json">
            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
            <CopyToPublishDirectory>Never</CopyToPublishDirectory>
        </None>
    </ItemGroup>
</Project>

All my referenced projects are netstandard2.1

Hope that helps

ghost commented 4 years ago

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.

moklas commented 4 years ago

@kevinbrydon thanks for the tip regarding AzureFunctionsVersion in the project file.

eliashdezr commented 4 years ago

I'm still having my issue described above: https://github.com/Azure/azure-functions-dotnet-extensions/issues/32#issuecomment-563500223

Only when I run the function with the cli func start --build works.

@fabiocav Is there some action already to make it work with Visual Studio again? I'm using the latest VS preview version.

StefanSchoof commented 4 years ago

I do not expires this bug any longer. @eliashdezr which value do you have at AzureFunctionsVersion in your csproj? v3 or v3-preview? If you still have v3-preview try to update to v3.

eliashdezr commented 4 years ago

I do not expires this bug any longer. @eliashdezr which value do you have at AzureFunctionsVersion in your csproj? v3 or v3-preview? If you still have v3-preview try to update to v3.

This is my csproj file:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <AzureFunctionsVersion>v3</AzureFunctionsVersion>
    <LangVersion>latest</LangVersion>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.0.0" />
    <PackageReference Include="Microsoft.Extensions.Http" Version="3.1.1" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.2" />
    <PackageReference Include="Utf8Json" Version="1.3.7" />
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\Demo.Data\Demo.Data.csproj" />
    <ProjectReference Include="..\Demo.Domain\Demo.Domain.csproj" />
    <ProjectReference Include="..\Demo.Services\Demo.Services.csproj" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
</Project>

And this is the installed runtime versions from the command line:

Azure Functions Core Tools (2.7.1948 Commit hash: 29a0626ded3ae99c4111f66763f27bb9fb564103)
Function Runtime Version: 2.0.12888.0
JohnGalt1717 commented 4 years ago

Same issue here, My project file is set to:

netcoreapp3.1 v3

Per the above and locally I still get the error:

ethod not found: 'Microsoft.Extensions.DependencyInjection.IServiceCollection Microsoft.Azure.Functions.Extensions.DependencyInjection.IFunctionsHostBuilder.get_Services()'. Value cannot be null. Parameter name: provider

dotnet --version: 3.1.101 func --version: 2.7.1948 (latest that I can get from Ubuntu apt based on the instructions on docs.microsoft.com, although the github site says that there is a newer version)

leighghunt commented 4 years ago

Just going to leave this here, as I've spent the last few hours trying to solve this myself, and found it was not code related but environment related, and to do with the azure-functions-core-tools tooling version I had being 2, rather than 3.

(Thanks to @IGx89 and others for tooling comments that caused me to focus on that)

More details incase it helps anyone else save some time - on a Mac but I imagine it will be the same for other environments:

Method not found: 'Microsoft.Extensions.DependencyInjection.IServiceCollection Microsoft.Azure.Functions.Extensions.DependencyInjection.IFunctionsHostBuilder.get_Services()'.
Value cannot be null.
Parameter name: provider

Resolution is to ensure you're using version 3 of azure-functions-core-tools.

Symptoms:

...
...
> Executing task: func host start <

                  %%%%%%
                 %%%%%%
            @   %%%%%%    @
          @@   %%%%%%      @@
       @@@    %%%%%%%%%%%    @@@
     @@      %%%%%%%%%%        @@
       @@         %%%%       @@
         @@      %%%       @@
           @@    %%      @@
                %%
                %

Azure Functions Core Tools (2.7.1948 Commit hash: 29a0626ded3ae99c4111f66763f27bb9fb564103)
Function Runtime Version: 2.0.12888.0
[31/01/20 12:19:44 AM] Building host: startup suppressed: 'False', configuration suppressed: 'False', startup operation id: '7baa2e3b-434f-49b2-9162-44ec76241027'
[31/01/20 12:19:44 AM] Reading host configuration file '/Users/leigh/dev/hnrg/apirepo/hnrgapi.functions/bin/Debug/netcoreapp3.1/host.json'
[31/01/20 12:19:44 AM] Host configuration file read:
[31/01/20 12:19:44 AM] {
[31/01/20 12:19:44 AM]   "version": "2.0"
[31/01/20 12:19:44 AM] }
[31/01/20 12:19:44 AM] Reading functions metadata
[31/01/20 12:19:44 AM] 1 functions found
[31/01/20 12:19:44 AM] Loading startup extension 'Startup'
[31/01/20 12:19:44 AM] Loaded extension 'Startup' (1.0.0.0)
[31/01/20 12:19:45 AM] A host error has occurred during startup operation '7baa2e3b-434f-49b2-9162-44ec76241027'.
[31/01/20 12:19:45 AM] hnrgapi.functions: Method not found: 'Microsoft.Extensions.DependencyInjection.IServiceCollection Microsoft.Azure.Functions.Extensions.DependencyInjection.IFunctionsHostBuilder.get_Services()'.
Value cannot be null.
Parameter name: provider
Application is shutting down...
[31/01/20 12:19:45 AM] Initialization cancellation requested by runtime.
Hosting environment: Production
Content root path: /Users/leigh/dev/hnrg/apirepo/hnrgapi.functions/bin/Debug/netcoreapp3.1
Now listening on: http://0.0.0.0:7071
Application started. Press Ctrl+C to shut down.
[31/01/20 12:19:45 AM] Stopping host...
[31/01/20 12:19:45 AM] Host shutdown completed.
The terminal process terminated with exit code: 1

Resolution:

In terminal:

$ brew uninstall azure-functions-core-tools
Uninstalling /usr/local/Cellar/azure-functions-core-tools/2.7.1948... (3,018 files, 430.3MB)

$ brew install azure-functions-core-tools@3
==> Installing azure-functions-core-tools@3 from azure/functions
==> Downloading https://functionscdn.azureedge.net/public/3.0.2009/Azure.Functions.Cli.osx-x64.3.0.2009.zip
Already downloaded: /Users/leigh/Library/Caches/Homebrew/downloads/079793bf4adfc986e99e65ce1488220d696a844b83b956d65260f2f3fa329789--Azure.Functions.Cli.osx-x64.3.0.2009.zip

 Telemetry 
 --------- 
 The Azure Functions Core tools collect usage data in order to help us improve your experience.
 The data is anonymous and doesn't include any user specific or personal information. The data is collected by Microsoft.

 You can opt-out of telemetry by setting the FUNCTIONS_CORE_TOOLS_TELEMETRY_OPTOUT environment variable to '1' or 'true' using your favorite shell.
🍺  /usr/local/Cellar/azure-functions-core-tools@3/3.0.2009: 3,125 files, 457.1MB, built in 22 seconds

The running in Code:

> Executing task: func host start <

                  %%%%%%
                 %%%%%%
            @   %%%%%%    @
          @@   %%%%%%      @@
       @@@    %%%%%%%%%%%    @@@
     @@      %%%%%%%%%%        @@
       @@         %%%%       @@
         @@      %%%       @@
           @@    %%      @@
                %%
                %

Azure Functions Core Tools (3.0.2009 Commit hash: 77395527a4e9c28da8400dcfd1a450f4e0d0c36c)
Function Runtime Version: 3.0.12930.0
[31/01/2020 12:26:13 AM] FUNCTIONS_WORKER_RUNTIME set to dotnet. Skipping WorkerConfig for language:python
[31/01/2020 12:26:13 AM] FUNCTIONS_WORKER_RUNTIME set to dotnet. Skipping WorkerConfig for language:java
[31/01/2020 12:26:13 AM] FUNCTIONS_WORKER_RUNTIME set to dotnet. Skipping WorkerConfig for language:powershell
[31/01/2020 12:26:13 AM] FUNCTIONS_WORKER_RUNTIME set to dotnet. Skipping WorkerConfig for language:node
[31/01/2020 12:26:14 AM] Building host: startup suppressed: 'False', configuration suppressed: 'False', startup operation id: '7453a75f-75b7-4ce1-81a5-2d689e456165'
[31/01/2020 12:26:14 AM] Reading host configuration file '/Users/leigh/dev/hnrg/apirepo/hnrgapi.functions/bin/Debug/netcoreapp3.1/host.json'
[31/01/2020 12:26:14 AM] Host configuration file read:
[31/01/2020 12:26:14 AM] {
[31/01/2020 12:26:14 AM]   "version": "2.0"
[31/01/2020 12:26:14 AM] }
[31/01/2020 12:26:14 AM] Reading functions metadata
[31/01/2020 12:26:15 AM] 1 functions found
[31/01/2020 12:26:15 AM] Loading startup extension 'Startup'
[31/01/2020 12:26:16 AM] Loaded extension 'Startup' (1.0.0.0)
...
...
Hosting environment: Production
Content root path: /Users/leigh/dev/hnrg/apirepo/hnrgapi.functions/bin/Debug/netcoreapp3.1
Now listening on: http://0.0.0.0:7071
Application started. Press Ctrl+C to shut down.

Http Functions:

        HttpTriggerCSharp: [GET,POST] http://localhost:7071/api/HttpTriggerCSharp

[31/01/2020 12:26:23 AM] Host lock lease acquired by instance ID '000000000000000000000000CC08CB69'.
JohnGalt1717 commented 4 years ago

Anyone know how to get the v3 version on Ubuntu? I can't even find the manual installer from the releases page for it.

leighghunt commented 4 years ago

Hi @eliashdezr - see my comment at https://github.com/Azure/azure-functions-dotnet-extensions/issues/29#issuecomment-580529424 - try updating your version of Azure Function Core Tools and see if that resolves it?

JohnGalt1717 commented 4 years ago

@leighghunt I'd love to. Can't find out how to get the v3 version on linux. Heck, the tools git release page doesn't even list V3.

leighghunt commented 4 years ago

Hi @JohnGalt1717, I'm guessing here, but try this:

sudo apt-get install azure-functions-core-tools=3
JohnGalt1717 commented 4 years ago

@leighghunt Doesn't work :<

plazav commented 4 years ago

I have the same issue with ASP.NET Core 3.1 application. It is works locally, but doesn't when it is published. It is published to Azure functions with Azure DevOps pipeline, but I can also publish it from VS 2019. Runtime version is set to ~3 WEBSITE_WEBDEPLOY_USE_SCM is set to false All packages are updated to latest stable version (3.1.1).

TargetFramework in all projects is netcoreapp3.1

v3

host.json is simple: { "version": "2.0" }

I have tried downgrade to 3.0 without any results.

kevinbrydon commented 4 years ago

@plazav Can you ensure the following things

Your .csproj file PropoertyGroup looks like this

...
<PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <AzureFunctionsVersion>v3</AzureFunctionsVersion>
</PropertyGroup>
...

Your host.json should be

{
    "version": "2.0"
}

In Azure Portal, your functions Runtime version is set to ~3.

If the above is all correct, it might be worth deleting and recreating your function in azure. Upgrade it to ~3 before deploying anything to it.

plazav commented 4 years ago

Hi @kevinbrydon, The settings that you have provided are correct. I have just recreated Function App (with new application name) and even have updated it to version 3 before publishing, but result is still same. Application is running on Linux and App Service Plan is used (not consumption plan), but I don't think that it could play any role.

kevinbrydon commented 4 years ago

@plazav Just to be clear. You're having the Method not found: 'Microsoft.Extensions.DependencyInjection.IServiceCollection Microsoft.Azure.Functions.Extensions.DependencyInjection.IFunctionsHostBuilder.get_Services() issue and not the Ubuntu issues? You're developing on a windows 10 machine?

Currently the only difference between me and you is that I am using the consumption plan.

If you are able to share your source code, pipeline script and function template then that might help.

plazav commented 4 years ago

@kevinbrydon Yes, I am having the issue "Method not found: 'Microsoft.Extensions.DependencyInjection.IServiceCollection Microsoft.Extensions.DependencyInjection.OptionsConfigurationServiceCollectionExtensions.Configure(Microsoft.Extensions.DependencyInjection.IServiceCollection, Microsoft.Extensions.Configuration.IConfiguration)'."

And yes, I am developing on Windows 10. Can provide some parts of my code (but what exactly?). Pipeline is not so much important as when I am publishing from VS result is the same.

Could it be that this issue happens because I have reference to <PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.2.0" /> in one of my projects? By the way the difference could be that I have multiple projects in my solution.

kevinbrydon commented 4 years ago

@plazav That error you are getting is different to the one being discussed in this thread. I don't think any of the solutions posted will help you. If it was me, I'd start from scratch. Simple function, no constructor, empty Startup (or a public override void Configure(IFunctionsHostBuilder builder) that does nothing) and try publish that. If it works, build it up from there until you hit the error.

Startup.cs

using Microsoft.Azure.Functions.Extensions.DependencyInjection;

[assembly: FunctionsStartup(typeof(My.Namespace.FunctionApp.Startup))]

namespace My.Namespace.FunctionApp
{
    public class Startup : FunctionsStartup
    {
        public override void Configure(IFunctionsHostBuilder builder)
        {
        }
    }
}
JohnGalt1717 commented 4 years ago

@kevinbrydon @plazav The bug you're getting is documented elsewhere and prevents overwritting IConfiguration within DI for things like loading Azure Keyvault. Do a search and you'll find the topic. Worked in 2.1, doesn't work in 3.1. There's a VERY ugly work around.

ghost commented 4 years ago

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.

linzomsft commented 4 years ago

@kevinbrydon @plazav The bug you're getting is documented elsewhere and prevents overwritting IConfiguration within DI for things like loading Azure Keyvault. Do a search and you'll find the topic. Worked in 2.1, doesn't work in 3.1. There's a VERY ugly work around.

Do you mind share What is work around? Thanks!

@plazav i am getting exactly the same issue you are getting during publish, nerver found it to be an issue running at my local environment.

leighghunt commented 4 years ago

@leighghunt Doesn't work :<

Hi @JohnGalt1717, I managed to get v3 of func working in a Ubuntu container.

I've tested this in a vanilla docker container (bionic image, so it's 18.04), so this should cover everything needed, and many steps probably not needed for you - just the last few.

I fire up the container like so:

docker run -ti ubuntu /bin/bash

Then, in that session, I run the following:

apt-get update
apt-get install -y wget unzip
wget -q https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
dpkg -i packages-microsoft-prod.deb
apt-get update
apt-get install -y dotnet-runtime-3.1
wget https://github.com/Azure/azure-functions-core-tools/releases/download/3.0.2009/Azure.Functions.Cli.linux-x64.3.0.2009.zip
unzip -d azure-functions-cli Azure.Functions.Cli.linux-x64.3.0.2009.zip
cd azure-functions-cli
chmod +x func
./func

More info:

I end up with:

root@c7f039870911:/azure-functions-cli# ./func

                  %%%%%%
                 %%%%%%
            @   %%%%%%    @
          @@   %%%%%%      @@
       @@@    %%%%%%%%%%%    @@@
     @@      %%%%%%%%%%        @@
       @@         %%%%       @@
         @@      %%%       @@
           @@    %%      @@
                %%
                %

Azure Functions Core Tools (3.0.2009 Commit hash: 77395527a4e9c28da8400dcfd1a450f4e0d0c36c)
Function Runtime Version: 3.0.12930.0
Usage: func [context] [context] <action> [-/--options]

Contexts:
azure       Commands to log in to Azure and manage resources
durable     Commands for working with Durable Functions
extensions  Commands for installing extensions
function    Commands for creating and running functions locally
host        Commands for running the Functions host locally
kubernetes  Commands for working with Kubernetes and Azure Functions
settings    Commands for managing environment settings for the local Functions host
templates   Commands for listing available function templates

Actions: 
start   Launches the functions runtime host  
    --port [-p]        Local port to listen on. Default: 7071
    --cors             A comma separated list of CORS origins with no spaces. Example: https://functions.azure.com,https://functions-staging.azure.com
    --cors-credentials Allow cross-origin authenticated requests (i.e. cookies and the Authentication header)
    --timeout [-t]     Timeout for on the functions host to start in seconds. Default: 20 seconds.
    --useHttps         Bind to https://localhost:{port} rather than http://localhost:{port}. By default it creates and trusts a certificate.
    --cert             for use with --useHttps. The path to a pfx file that contains a private key
    --password         to use with --cert. Either the password, or a file that contains the password for the pfx file
    --language-worker  Arguments to configure the language worker.
    --no-build         Do no build current project before running. For dotnet projects only. Default is set to false.
    --enableAuth       Enable full authentication handling pipeline.
    --functions        A space seperated list of functions to load.

new     Create a new function from a template. Aliases: new, create
    --language [-l] Template programming language, such as C#, F#, JavaScript, etc.
    --template [-t] Template name
    --name [-n]     Function name
    --csx           use old style csx dotnet functions

init    Create a new Function App in the current folder. Initializes git repo.  
    --source-control       Run git init. Default is false.
    --worker-runtime       Runtime framework for the functions. Options are: dotnet, node, python, powershell
    --force                Force initializing
    --docker               Create a Dockerfile based on the selected worker runtime
    --docker-only          Adds a Dockerfile to an existing function app project. Will prompt for worker-runtime if not specified or set in local.settings.json
    --csx                  use csx dotnet functions
    --language             Initialize a language specific project. Currently supported when --worker-runtime set to node. Options are - "typescript" and "javascript"
    --managed-dependencies Installs managed dependencies. Currently, only the PowerShell worker runtime supports this functionality.

logs    Gets logs of Functions running on custom backends  
    --platform Hosting platform for the function app. Valid options: kubernetes
    --name     Function name
JohnGalt1717 commented 4 years ago

@leighghunt Thanks. That's ultimately what I ended up doing too. It's really ugly and the only platform that makes you go through such hoops.

And if you look at the official approach, it's also at least 1 version of V2 behind for over a week as well.

This needs to be addressed so that packages are both released at the same time as everyone else gets them, and there's an easy and managed way to get beta channel releases. (especially when Azure Functions is so far behind in releasing current versions for .NET Core and the last version supported (.net 2.2) is no longer supported by MS forcing us all to use beta versions of Azure Functions or have major issues.

I'd suggest moving to npm like on Windows. Or Snaps with channels.

ghost commented 4 years ago

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.

eliashdezr commented 4 years ago

This should not be closed...

JohnGalt1717 commented 4 years ago

Ya, this should be reopened because the issue is still there: This needs to be addressed by the team so that it's possible to actually get these on linux etc.

VQuery commented 4 years ago

Issue still exists in latest version.

jeffhollan commented 4 years ago

Reading through this issue, I think one of the problems is there seems to be a lot going on here. Everything from needing to make sure you are setting to ~3 in the cloud, using the v3 version of the core tools, and an updated version of the host that went out a few weeks back. I’m not saying there aren’t valid issues occurring, the the original post very likely could be resolved by one of those fixes (and a few others in the thread). For folks who are still hitting other issues, please feel free to open or flag a different issue. Please be sure to include as much detail as possible into what errors or issues you are hitting so we can track correctly. Want to make sure we resolve any issues that are occurring without also accidentally tracking 4 very different issues all under the same one.

MichalKosowski commented 4 years ago

Hi,

How about running sudo apt-get install azure-functions-core-tools-3

That fixed the problem for me for Ubuntu on WSL (found this here: https://github.com/Azure/azure-functions-core-tools)

leighghunt commented 4 years ago

Hi,

How about running sudo apt-get install azure-functions-core-tools-3

That fixed the problem for me for Ubuntu on WSL (found this here: https://github.com/Azure/azure-functions-core-tools)

Sweet - this now appears to be running, follwing https://github.com/Azure/azure-functions-core-tools/commit/3f2771101d72615dcb46bbd1edc529489b1f2a0c

My earlier test in docker container is now much shorter:

docker run -ti ubuntu /bin/bash

In that session:

apt-get update
apt-get install -y wget unzip
wget -q https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
dpkg -i packages-microsoft-prod.deb
apt-get update
apt-get install azure-functions-core-tools-3

The running func:

root@702d83c30c66:/# func

                  %%%%%%
                 %%%%%%
            @   %%%%%%    @
          @@   %%%%%%      @@
       @@@    %%%%%%%%%%%    @@@
     @@      %%%%%%%%%%        @@
       @@         %%%%       @@
         @@      %%%       @@
           @@    %%      @@
                %%
                %

Azure Functions Core Tools (3.0.2245 Commit hash: 1d094e2f3ef79b9a478a1621ea7ec3f93ac1910d)
Function Runtime Version: 3.0.13139.0
Usage: func [context] [context] <action> [-/--options]

Contexts:
azure       Commands to log in to Azure and manage resources
durable     Commands for working with Durable Functions
extensions  Commands for installing extensions
function    Commands for creating and running functions locally
host        Commands for running the Functions host locally
kubernetes  Commands for working with Kubernetes and Azure Functions
settings    Commands for managing environment settings for the local Functions host
templates   Commands for listing available function templates

Actions: 
start   Launches the functions runtime host  
    --port [-p]        Local port to listen on. Default: 7071
    --cors             A comma separated list of CORS origins with no spaces. Example: https://functions.azure.com,https://functions-staging.azure.com
    --cors-credentials Allow cross-origin authenticated requests (i.e. cookies and the Authentication header)
    --timeout [-t]     Timeout for on the functions host to start in seconds. Default: 20 seconds.
    --useHttps         Bind to https://localhost:{port} rather than http://localhost:{port}. By default it creates and trusts a certificate.
    --cert             for use with --useHttps. The path to a pfx file that contains a private key
    --password         to use with --cert. Either the password, or a file that contains the password for the pfx file
    --language-worker  Arguments to configure the language worker.
    --no-build         Do no build current project before running. For dotnet projects only. Default is set to false.
    --enableAuth       Enable full authentication handling pipeline.
    --functions        A space seperated list of functions to load.

new     Create a new function from a template. Aliases: new, create
    --language [-l] Template programming language, such as C#, F#, JavaScript, etc.
    --template [-t] Template name
    --name [-n]     Function name
    --csx           use old style csx dotnet functions

init    Create a new Function App in the current folder. Initializes git repo.  
    --source-control       Run git init. Default is false.
    --worker-runtime       Runtime framework for the functions. Options are: dotnet, node, python, powershell
    --force                Force initializing
    --docker               Create a Dockerfile based on the selected worker runtime
    --docker-only          Adds a Dockerfile to an existing function app project. Will prompt for worker-runtime if not specified or set in local.settings.json
    --csx                  use csx dotnet functions
    --language             Initialize a language specific project. Currently supported when --worker-runtime set to node. Options are - "typescript" and "javascript"
    --managed-dependencies Installs managed dependencies. Currently, only the PowerShell worker runtime supports this functionality.

logs    Gets logs of Functions running on custom backends  
    --platform Hosting platform for the function app. Valid options: kubernetes
    --name     Function name
eliashdezr commented 4 years ago

I posted a sample to reproduce the DependencyInjection error with the minimum stuff here:

https://github.com/Azure/azure-functions-dotnet-extensions/issues/36#issuecomment-594979004

JohnGalt1717 commented 4 years ago

@leighghunt As previously stated, that works NOW because the final version has been released. The issue is that pre-releases cannot be pulled any other way but manually right now and it needs to be corrected so that Linux has parity with Windows and Mac.