Azure-docs: example does not work

Created on 9 Mar 2020  Â·  7Comments  Â·  Source: MicrosoftDocs/azure-docs

That Startup.cs example DOES NOT WORK

Method not found: 'Microsoft.Extensions.DependencyInjection.IServiceCollection Microsoft.Azure.Functions.Extensions.DependencyInjection.IFunctionsHostBuilder.get_Services()'.


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Pri1 azure-functionsvc cxp product-question triaged

All 7 comments

@uranio-235 Thank you for your feedback! This is most likely an issue in your local environment. Could you specify which version of Functions runtime you have tried this with?

Here's couple of resources that might help:

  1. A complete sample that I have tested: https://github.com/mike-urnun-msft/AzureFunkDI
  2. An existing issue where others are discussing different solutions that worked for them: https://github.com/Azure/azure-functions-dotnet-extensions#29

@uranio-235 Thank you for your feedback! This is most likely an issue in your local environment. Could you specify which version of Functions runtime you have tried this with?

Thanks for you answer. I'm using VisualStudio 2019, just created azure function time triggers and follow such steps.

[10/3/2020 19:15:45] Building host: startup suppressed: 'False', configuration suppressed: 'False', startup operation id: 'a86e9ee9-9a4c-4960-9ad9-9cb89b1266f6'
[10/3/2020 19:15:45] Reading host configuration file 'C:\Users\lazaro\source\repos\WealFunction\WealFunction\bin\Debug\netcoreapp2.1\host.json'
[10/3/2020 19:15:45] Host configuration file read:
[10/3/2020 19:15:45] {
[10/3/2020 19:15:45]   "version": "2.0"
[10/3/2020 19:15:45] }
[10/3/2020 19:15:45] Reading functions metadata
[10/3/2020 19:15:45] 1 functions found
[10/3/2020 19:15:45] Loading startup extension 'Startup'
[10/3/2020 19:15:45] Loaded extension 'Startup' (1.0.0.0)
[10/3/2020 19:15:45] A host error has occurred during startup operation 'a86e9ee9-9a4c-4960-9ad9-9cb89b1266f6'.
[10/3/2020 19:15:45] WealFunction: Method not found: 'Microsoft.Extensions.DependencyInjection.IServiceCollection Microsoft.Azure.Functions.Extensions.DependencyInjection.IFunctionsHostBuilder.get_Services()'.

As you can see, version is 2. This is my project file:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netcoreapp2.1</TargetFramework>
    <AzureFunctionsVersion>v2</AzureFunctionsVersion>
  </PropertyGroup>

Example neither work

https://github.com/mike-urnun-msft/AzureFunkDI

[10/3/2020 19:44:57] Executed 'SampleFunction' (Failed, Id=ba2076d8-cd6e-4b59-8509-95e48f0fe607)
[10/3/2020 19:44:57] Microsoft.Extensions.DependencyInjection.Abstractions: Unable to resolve service for type 'Microsoft.Azure.Functions.Samples.DependencyInjectionBasic.IGreeter' while attempting to activate 'Microsoft.Azure.Functions.Samples.DependencyInjectionBasic.SampleFunction'.
[10/3/2020 19:44:58] An unhandled host error has occurred.
[10/3/2020 19:44:58] Microsoft.Extensions.DependencyInjection.Abstractions: Unable to resolve service for type 'Microsoft.Azure.Functions.Samples.DependencyInjectionBasic.IGreeter' while attempting to activate 'Microsoft.Azure.Functions.Samples.DependencyInjectionBasic.SampleFunction'.

@uranio-235 Could you share your code in Startup.cs as well as in WealFunction.cs files? For getting the exact runtime version, in your command line, you can type in func and it should show as below:
image

Sample in my repo is working fine on VS2019 with the azure-functions-core-tools and Functions runtime versions as shown in the screenshot above.

@uranio-235 Since this channel is for driving improvements towards MS Docs and we haven't determined any faulty steps in this documentation from our review, we will now proceed to close this thread. If there are further questions regarding this matter, please engage the existing issue where the Functions team and the rest of Functions community may weigh in on the particular issue that you're encountering.

Executed 'MyFunctionApp' (Failed, Id=ba2076d8-cd6e-4b59-8509-95e48f0fe607)
I'm getting same error. Any resolve?

Sorry my late, connection problems, this is my Startup.cs

using System;
using Microsoft.Azure.Functions.Extensions.DependencyInjection;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using WealFunction.Abstract;
using WealFunction.Data;
using WealFunction.Models.Entities;

// Fix this error:
// Method not found: 'Microsoft.Extensions.DependencyInjection.IServiceCollection
// Microsoft.Azure.Functions.Extensions.DependencyInjection.IFunctionsHostBuilder.get_Services()'.
[assembly: FunctionsStartup(typeof(WealFunction.Startup))]

namespace WealFunction
{
    public class Startup : FunctionsStartup
    {
        public override void Configure(IFunctionsHostBuilder builder)
        {
            builder.Services.AddDbContext<AppDbContext>();
            builder.Services.AddTransient(typeof(IRepository<>), typeof(EFRepository<>));
            builder.Services.AddTransient<User>();
        }

    } // class
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

behnam89 picture behnam89  Â·  3Comments

Ponant picture Ponant  Â·  3Comments

DeepPuddles picture DeepPuddles  Â·  3Comments

JamesDLD picture JamesDLD  Â·  3Comments

varma31 picture varma31  Â·  3Comments